-
Notifications
You must be signed in to change notification settings - Fork 56
Usage: 1) Working with certificate
Lucas Nepomuceno edited this page Jan 5, 2022
·
3 revisions
<?php
use LSNepomuceno\LaravelA1PdfSign\ManageCert;
class ExampleController() {
public function dummyFunction(){
try {
$cert = new ManageCert;
$cert->setPreservePfx() // If you need to preserve the PFX certificate file
->fromPfx('path/to/certificate.pfx', 'password');
dd($cert->getCert());
} catch (\Throwable $th) {
// TODO necessary
}
}
}
<?php
use Illuminate\Http\Request;
use LSNepomuceno\LaravelA1PdfSign\ManageCert;
class ExampleController() {
public function dummyFunction(Request $request){
try {
$cert = new ManageCert;
$cert->fromUpload($request->pfxUploadedFile, $request->password);
dd($cert->getCert());
} catch (\Throwable $th) {
// TODO necessary
}
}
}
<?php
use App\Models\Certificate;
use LSNepomuceno\LaravelA1PdfSign\ManageCert;
class ExampleController() {
public function dummyFunction(){
try {
$cert = new ManageCert;
$cert->fromPfx('path/to/certificate.pfx', 'password');
} catch (\Throwable $th) {
// TODO necessary
}
// Postgres or MS SQL Server
Certificate::create([
'certificate' => $cert->getEncrypter()->encryptString($cert->getCert()->original)
'password' => $cert->getEncrypter()->encryptString('password'),
'hash' => $cert->getHashKey(), // IMPORTANT
...
]);
// For MySQL
Certificate::create([
'certificate' => $cert->encryptBase64BlobString($cert->getCert()->original)
'password' => $cert->getEncrypter()->encryptString('password'),
'hash' => $cert->getHashKey(), // IMPORTANT
...
]);
}
}
<?php
use LSNepomuceno\LaravelA1PdfSign\ManageCert;
class CertificateModel() {
public function parse(): ?ManageCert {
try {
// IMPORTANT
// Set true if you only use the "encryptBase64BlobString" method
return decryptCertData($this->hash, $this->certificate, $this->password, true);
} catch (\Throwable $th) {
// TODO necessary
}
}
}