Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hsmcrypto
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mohammad Izzat Johari
hsmcrypto
Commits
3c97bed0
Commit
3c97bed0
authored
Dec 26, 2025
by
Mohammad Izzat Johari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
503e956e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
67 deletions
+6
-67
src/Pkcs11Command.php
+6
-67
No files found.
src/Pkcs11Command.php
View file @
3c97bed0
...
@@ -7,6 +7,7 @@ use Illuminate\Support\Str;
...
@@ -7,6 +7,7 @@ use Illuminate\Support\Str;
use
Illuminate\Support\Facades\File
;
use
Illuminate\Support\Facades\File
;
use
LaravelHsm\HsmCrypto\Models\HsmLog
;
use
LaravelHsm\HsmCrypto\Models\HsmLog
;
use
setasign\Fpdi\Fpdi
;
use
setasign\Fpdi\Fpdi
;
use
setasign\Fpdi\PdfParser\StreamReader
;
class
Pkcs11Command
class
Pkcs11Command
{
{
...
@@ -254,69 +255,6 @@ 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
)
protected
function
encryptAesKey
(
string
$aesKey
,
string
$filename
)
{
{
...
@@ -450,11 +388,12 @@ class Pkcs11Command
...
@@ -450,11 +388,12 @@ class Pkcs11Command
$fpdi
=
new
MyPdf
();
$fpdi
=
new
MyPdf
();
// Write decrypted bytes to a memory stream
// Write decrypted bytes to a memory stream
$pdfStream
=
fopen
(
'php://memory'
,
'r+'
);
//
$pdfStream = fopen('php://memory', 'r+');
fwrite
(
$pdfStream
,
$decryptedPdf
);
//
fwrite($pdfStream, $decryptedPdf);
rewind
(
$pdfStream
);
//
rewind($pdfStream);
// Count pages
// Count pages
$pdfStream
=
StreamReader
::
createByString
(
$decryptedPdf
);
$pageCount
=
$fpdi
->
setSourceFile
(
$pdfStream
);
$pageCount
=
$fpdi
->
setSourceFile
(
$pdfStream
);
// 3️⃣ Add watermark & rebuild PDF in memory
// 3️⃣ Add watermark & rebuild PDF in memory
...
@@ -473,7 +412,7 @@ class Pkcs11Command
...
@@ -473,7 +412,7 @@ class Pkcs11Command
$watermarkText
=
auth
()
->
user
()
->
name
.
" | "
.
date
(
"d/m/y"
)
.
" | "
.
date
(
"h:i:s A"
);
$watermarkText
=
auth
()
->
user
()
->
name
.
" | "
.
date
(
"d/m/y"
)
.
" | "
.
date
(
"h:i:s A"
);
$angle
=
45
;
// diagonal
$angle
=
45
;
// diagonal
$spacing
=
8
0
;
// distance between stripes
$spacing
=
3
0
;
// distance between stripes
for
(
$x
=
-
50
;
$x
<
$size
[
'width'
]
+
200
;
$x
+=
$spacing
)
{
for
(
$x
=
-
50
;
$x
<
$size
[
'width'
]
+
200
;
$x
+=
$spacing
)
{
for
(
$y
=
0
;
$y
<
$size
[
'height'
]
+
200
;
$y
+=
$spacing
)
{
for
(
$y
=
0
;
$y
<
$size
[
'height'
]
+
200
;
$y
+=
$spacing
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment