openssl_pkcs7_sign(): error getting private key

冷暖自知 提交于 2020-05-27 18:34:12

问题


When trying to use TCPDF to generate a pdf and sign it, i get the error:

openssl_pkcs7_sign(): error getting private key.

and:

Undefined offset: 1 in ..\tcpdf\tcpdf.php on line 7604

I have found the following stackoverflow posts and tried to follow their solutions:

  • Warning: openssl_pkcs7_sign(): error getting private key using WAMP
  • Warning: openssl_pkcs7_sign() [function.openssl-pkcs7-sign]: error getting private key in C:\xampp\htdocs\this\tcpdf\tcpdf.php on line 8366

Unfortunately, nothing works.

I have tried to use:

$certificate = "file://" . getcwd() . "/objects/dummy_cert.cert";

or

$certificate = "file://" . __DIR__ "/objects/dummy_cert.cert";

or writing the absolute path by hand.

My script is executed from the project root path, from which /objects/ is the next folder in which my dummy_cert.cert lies.

What is happening here and how can i fix this?

I even logged the content of $certificate to be sure it generates the correct path. The generated path, copied into Google Chrome address bar, immediately loads the content of the .cert file.


回答1:


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

//in your case
$certificate = 'file://'.realpath('/objects/dummy_cert.cert');
// OR for other cases
$certificate = 'file://'.realpath('../upper_folder/objects/dummy_cert.cert');
// OR
$certificate = 'file://'.realpath('C:/objects/dummy_cert.cert');


来源:https://stackoverflow.com/questions/40160628/openssl-pkcs7-sign-error-getting-private-key

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!