Warning: openssl_pkcs7_sign(): error getting priva

2020-03-24 05:29发布

问题:

I am trying to sign PDF using TCPDF, but I have got this error:

Warning: openssl_pkcs7_sign(): error getting private key in C:\wamp\www\tcpdf\tcpdf.php on line 7594.   

My PHP version is 5.5.12 and TCPDF 6.2.11. Windows 7.

Other examples run well but this fails. I have tried:

'file://'.( dirname(FILE)).'./path/to/file' and again $certificate = 'file://'.realpath('../tcpdf.crt'); 

but does not work for me.

回答1:

I think file:// is not correct. You fetch die real path with dirname(__FILE__) that should be enough. So i prefer:

$certificate = __DIR__'/../tcpdf.crt';

__DIR__ or dirname(FILE) is the path to the file you've in. To you can go back with /../../ to your file depends on your folder location for your certificate files.



回答2:

You need the 'file://' prefix and the realpath to file:

//in your case
$certificate = 'file://'.realpath('../tcpdf.crt');
// OR for other cases
$certificate = 'file://'.realpath('/tcpdf.crt');
// OR
$certificate = 'file://'.realpath('C:/tcpdf.crt');