1 - Reading the certificate from file.
<?php
use LSNepomuceno\LaravelA1PdfSign\Sign\ManageCert;
class ExampleController() {
public function dummyFunction(){
try {
$cert = new ManageCert;
$cert->setPreservePfx()
->fromPfx('path/to/certificate.pfx', 'password');
dd($cert->getCert());
} catch (\Throwable $th) {
}
}
}
2 - Reading the certificate from upload.
<?php
use Illuminate\Http\Request;
use LSNepomuceno\LaravelA1PdfSign\Sign\ManageCert;
class ExampleController() {
public function dummyFunction(Request $request){
try {
$cert = new ManageCert;
$cert->fromUpload($request->pfxUploadedFile, $request->password);
dd($cert->getCert());
} catch (\Throwable $th) {
}
}
}
3 - The expected result will be as shown below.

4 - Store certificate data securely in the database.
IMPORTANT: Store certificate columns as binary data type
<?php
use App\Models\Certificate;
use LSNepomuceno\LaravelA1PdfSign\Sign\ManageCert;
class ExampleController() {
public function dummyFunction(){
try {
$cert = new ManageCert;
$cert->fromPfx('path/to/certificate.pfx', 'password');
} catch (\Throwable $th) {
}
Certificate::create([
'certificate' => $cert->getEncrypter()->encryptString($cert->getCert()->original)
'password' => $cert->getEncrypter()->encryptString('password'),
'hash' => $cert->getHashKey(),
...
]);
Certificate::create([
'certificate' => $cert->encryptBase64BlobString($cert->getCert()->original)
'password' => $cert->getEncrypter()->encryptString('password'),
'hash' => $cert->getHashKey(),
...
]);
}
}
5 - Reading certificate from database (model based).
<?php
use LSNepomuceno\LaravelA1PdfSign\Sign\ManageCert;
class CertificateModel() {
public function parse(): ?ManageCert {
try {
return decryptCertData($this->hash, $this->certificate, $this->password, true);
} catch (\Throwable $th) {
}
}
}