无法使用PHP openssl_sign进行任何签名? [英] Cannot sign anything with PHP openssl_sign?

查看:1566
本文介绍了无法使用PHP openssl_sign进行任何签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP-DKIM发送DKIM签名的电子邮件.它有点旧了,所以我不得不改变一些东西,但这让我很困惑:

I am attempting to use PHP-DKIM to send DKIM signed emails. Its a little old so I've had to change some things, but this stumps me:

Warning: openssl_sign() [function.openssl-sign]: supplied key param cannot be coerced into a private key in /.../pages/user/dkim.php on line 66
Cannot sign

代码的相关部分(请注意,我已经添加了$ pkeyid,最初私钥只是直接传递给了open_ssl函数,该函数也不起作用)

Relevant section of code (note I've added the $pkeyid, originally the private key was just passed straight to the open_ssl function which also didn't work)

$pkeyid = openssl_get_privatekey($open_SSL_priv);
if (openssl_sign($s, $signature, $pkeyid))
    return base64_encode($signature) ;
else
    die("Cannot sign") ;

因此,很显然这里确实发生了一些糟糕的事情.但是我知道我的私钥和公钥是有效的.我什至尝试了 openssl_sign 无效

So obviously something really bad is going on here. However I know my private key and public key are valid. I even tried the example key provided in the comments for openssl_sign which didn't work

$open_SSL_pub=<<<EOD
-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANDiE2+Xi/WnO+s120NiiJhNyIButVu6
zxqlVzz0wy2j4kQVUC4ZRZD80IY+4wIiX2YxKBZKGnd2TtPkcJ/ljkUCAwEAAQ==
-----END PUBLIC KEY-----
EOD;

$open_SSL_priv=<<<EOD
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBANDiE2+Xi/WnO+s120NiiJhNyIButVu6zxqlVzz0wy2j4kQVUC4Z
RZD80IY+4wIiX2YxKBZKGnd2TtPkcJ/ljkUCAwEAAQJAL151ZeMKHEU2c1qdRKS9
sTxCcc2pVwoAGVzRccNX16tfmCf8FjxuM3WmLdsPxYoHrwb1LFNxiNk1MXrxjH3R
6QIhAPB7edmcjH4bhMaJBztcbNE1VRCEi/bisAwiPPMq9/2nAiEA3lyc5+f6DEIJ
h1y6BWkdVULDSM+jpi1XiV/DevxuijMCIQCAEPGqHsF+4v7Jj+3HAgh9PU6otj2n
Y79nJtCYmvhoHwIgNDePaS4inApN7omp7WdXyhPZhBmulnGDYvEoGJN66d0CIHra
I2SvDkQ5CmrzkW5qPaE2oO7BSqAhRZxiYpZFb5CI
-----END RSA PRIVATE KEY-----
EOD;

我不知所措. OpenSSL"0.9.8e-fips-rhel5 2008年7月1日"已安装并在PHP中处于活动状态.我生成的密钥和该密钥都可以正常工作.那么为什么openssl_sign一直失败?

I'm at a loss of what to do. OpenSSL "0.9.8e-fips-rhel5 01 Jul 2008" is installed and active in PHP. Both the key I generated and that key are known working. So why does openssl_sign keep failing?

推荐答案

使用PHP-DKIM时发生相同的错误

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.

但是,我的问题是我将PHP-DKIM脚本包含在一个函数中.

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

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

包括函数外的文件停止了错误.

including the file outside the function stopped the error.

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

我希望这会有所帮助.

这篇关于无法使用PHP openssl_sign进行任何签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆