note 88645 modified in function.openssl-pkcs-sign by danbrown
| From: | danbrown@php.net | Date: | Mon, 09 Feb 2009 22:05:19 +0000 |
| Subject: | note 88645 modified in function.openssl-pkcs-sign by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150428@lists.php.net to get a copy of this message | ||
I also spent hours when trying to find the reason of error:
"error getting private key".
Sometimes this error appeared, sometimes not.
My solution is using the realpath() for every parameter of openssl_pkcs7_sign. In my case the code
looks like:
<?php
$Certif_path = 'certificate/mycertificate.pem';
$clearfile = "certificate/random_name";
$encfile = $clearfile . ".enc";
$clearfile = $clearfile . ".txt";
// ----
// -- fill $clearfile with the mail to be signed ...
// ----
openssl_pkcs7_sign(realpath($clearfile),
realpath('.').'/'.$encfile, // because $encfile does
not exist yet we cannot use realpath($encfile);
'file://'.realpath($Certif_path),
array('file://'.realpath($Certif_path), PUBLIC_KEY),
array("To" => TO_EMAIL,
"From" => FROM_EMAIL,
"Subject" => ""),
PKCS7_DETACHED));
?>
--was--
I also spent hours when trying to find the reason of error:
"error getting private key".
Sometimes this error appeared, sometimes not.
My solution is using the realpath() for every parameter of openssl_pkcs7_sign. In my case the code
looks like:
<?php
$Certif_path = 'certificate/mycertificate.pem';
$clearfile = "certificate/random_name";
$encfile = $clearfile . ".enc";
$clearfile = $clearfile . ".txt";
// ----
// -- fill $clearfile with the mail to be signed ...
// ----
openssl_pkcs7_sign(realpath($clearfile),
realpath('.').'/'.$encfile, // because $encfile does
not exist yet we cannot use realpath($encfile);
'file://'.realpath($Certif_path),
array('file://'.realpath($Certif_path), PUBLIC_KEY),
array("To" => TO_EMAIL,
"From" => FROM_EMAIL,
"Subject" => ""),
PKCS7_DETACHED));
?>
http://php.net/manual/en/function.openssl-pkcs-sign.php