Commit 3c97bed0 by Mohammad Izzat Johari

fix bug

parent 503e956e
......@@ -7,6 +7,7 @@ use Illuminate\Support\Str;
use Illuminate\Support\Facades\File;
use LaravelHsm\HsmCrypto\Models\HsmLog;
use setasign\Fpdi\Fpdi;
use setasign\Fpdi\PdfParser\StreamReader;
class Pkcs11Command
{
......@@ -254,69 +255,6 @@ class Pkcs11Command
}
}
/**
* Encrypt AES key using HSM.
*/
// protected function encryptAesKey(string $aesKey, string $filename)
// {
// $id_key = $this->getkeypairIdByLabel($this->keyLabel);
// $storagePath = public_path("storage/hsm/encryptkey");
// if (!File::exists($storagePath)) {
// File::makeDirectory($storagePath, 0777, true);
// }
// $encryptedKeyPath = $storagePath . '/' . Str::beforeLast($filename, '.') . '.key.enc';
// $cmd = '"' . $this->pkcs11_tool . '"'
// . ' --module "' . $this->module . '"'
// . ' --slot ' . $this->slotId
// . ' --login'
// . ' --pin "' . $this->pin . '"'
// . ' --id ' . $id_key
// . ' --encrypt'
// . ' --mechanism RSA-PKCS-OAEP'
// . ' --output-file "' . $encryptedKeyPath . '"';
// $pipes = [];
// $process = proc_open($cmd, [
// 0 => ["pipe", "r"], // stdin
// 1 => ["pipe", "w"], // stdout
// 2 => ["pipe", "w"], // stderr
// ], $pipes);
// if (!is_resource($process)) {
// throw new \RuntimeException("Failed to start pkcs11-tool process.");
// }
// fwrite($pipes[0], $aesKey);
// fclose($pipes[0]);
// $stdout = stream_get_contents($pipes[1]);
// $stderr = stream_get_contents($pipes[2]);
// fclose($pipes[1]);
// fclose($pipes[2]);
// $returnCode = proc_close($process);
// if ($returnCode !== 0) {
// Log::error("Failed to encrypt AES key", [
// 'stdout' => $stdout,
// 'stderr' => $stderr,
// 'code' => $returnCode,
// ]);
// $this->logger('AES Key Encrypted', '', 'AES Key Encrypted Failed');
// throw new \RuntimeException("Failed to encrypt AES key: $stderr");
// }
// Log::info('AES key encrypted', ['path' => $encryptedKeyPath]);
// $this->logger('AES Key Encrypted', '', 'AES Key Encrypted Successful');
// return $encryptedKeyPath;
// }
protected function encryptAesKey(string $aesKey, string $filename)
{
......@@ -450,11 +388,12 @@ class Pkcs11Command
$fpdi = new MyPdf();
// Write decrypted bytes to a memory stream
$pdfStream = fopen('php://memory', 'r+');
fwrite($pdfStream, $decryptedPdf);
rewind($pdfStream);
// $pdfStream = fopen('php://memory', 'r+');
// fwrite($pdfStream, $decryptedPdf);
// rewind($pdfStream);
// Count pages
$pdfStream = StreamReader::createByString($decryptedPdf);
$pageCount = $fpdi->setSourceFile($pdfStream);
// 3️⃣ Add watermark & rebuild PDF in memory
......@@ -473,7 +412,7 @@ class Pkcs11Command
$watermarkText = auth()->user()->name . " | " . date("d/m/y") . " | " . date("h:i:s A");
$angle = 45; // diagonal
$spacing = 80; // distance between stripes
$spacing = 30; // distance between stripes
for ($x = -50; $x < $size['width'] + 200; $x += $spacing) {
for ($y = 0; $y < $size['height'] + 200; $y += $spacing) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment