Cannot sign anything with PHP openssl_sign?

眉间皱痕 提交于 2019-12-01 09:58:19

I had the same error occur using PHP-DKIM

Without seeing the rest of your code, It's difficult to see if it is for the same reason.

However, my issue was that I was including the PHP-DKIM script inside a function.

ie

function sendEmail(){
require 'dkim.php';
//DO STUFF HERE
}

including the file outside the function stopped the error.

ie

require 'dkim.php';
function sendEmail(){
//DO STUFF HERE
}

I hope this helps.

user2778850

I had this issue today, and the problem was slightly different; I had my privateKey as string in PHP, rather than stored in a file and retrieved using file_get_contents. As soon as I switched to a file-based solution, everything started to work.

Personally, I would recommend phpseclib, a pure PHP RSA implementation, be used. eg.

<?php
$rsa = new Crypt_RSA();
$rsa->loadKey(file_get_contents('privatekey.txt'));
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
file_put_contents('signature.txt', $rsa->sign(file_get_contents('plaintext.txt')));
?>

That is fully interoperable with OpenSSL as the following demonstrates:

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