@@ -22,7 +22,6 @@ public function sign(JSignParam $params)
2222 {
2323 try {
2424 $ this ->validation ($ params );
25- $ this ->repackCertificateIfPasswordIsUnicode ($ params );
2625
2726 $ commandSign = $ this ->commandSign ($ params );
2827 \exec ($ commandSign , $ output );
@@ -57,12 +56,11 @@ public function sign(JSignParam $params)
5756 * unicode chars. As workaround, I changed the password certificate in
5857 * memory.
5958 */
60- private function repackCertificateIfPasswordIsUnicode (JSignParam $ params )
59+ private function repackCertificateIfPasswordIsUnicode (JSignParam $ params, $ cert , $ pkey )
6160 {
6261 if (!mb_detect_encoding ($ params ->getPassword (), 'ASCII ' , true )) {
6362 $ password = md5 (microtime ());
64- $ certInfo = $ this ->pkcs12Read ($ params );
65- $ newCert = $ this ->exportToPkcs12 ($ certInfo ['cert ' ], $ certInfo ['pkey ' ], $ password );
63+ $ newCert = $ this ->exportToPkcs12 ($ cert , $ pkey , $ password );
6664 $ params ->setPassword ($ password );
6765 $ params ->setCertificate ($ newCert );
6866 }
@@ -86,7 +84,7 @@ public function getVersion(JSignParam $params)
8684 return explode ('version ' , $ lastRow )[1 ];
8785 }
8886
89- private function validation (JSignParam $ params )
87+ public function validation (JSignParam $ params )
9088 {
9189 $ this ->throwIf (empty ($ params ->getTempPath ()) || !is_writable ($ params ->getTempPath ()), 'Temp Path is invalid or has not permission to writable. ' );
9290 $ this ->throwIf (empty ($ params ->getPdf ()), 'PDF is Empty or Invalid. ' );
@@ -175,6 +173,7 @@ private function pkcs12Read(JSignParam $params)
175173 $ certificate = $ params ->getCertificate ();
176174 $ password = $ params ->getPassword ();
177175 if (openssl_pkcs12_read ($ certificate , $ certInfo , $ password )) {
176+ $ this ->repackCertificateIfPasswordIsUnicode ($ params , $ certInfo ['cert ' ], $ certInfo ['pkey ' ]);
178177 return $ certInfo ;
179178 }
180179 $ msg = openssl_error_string ();
@@ -200,6 +199,7 @@ private function pkcs12Read(JSignParam $params)
200199 unlink ($ tempEncriptedRepacked );
201200 unlink ($ tempDecrypted );
202201 openssl_pkcs12_read ($ certificateRepacked , $ certInfo , $ password );
202+ $ this ->repackCertificateIfPasswordIsUnicode ($ params , $ certInfo ['cert ' ], $ certInfo ['pkey ' ]);
203203 return $ certInfo ;
204204 }
205205 return [];
0 commit comments