我正在尝试使用我的私钥生成数据签名。
此代码适用于我的本地计算机,而openssl_pkey_get_private
始终在我的开发服务器上返回false,因此失败。我得到openssl_sign(): supplied key param cannot be coerced into a private key
。服务器有什么问题吗?我是否需要修改任何服务器配置?
class MyClass {
protected $pub = <<< EOT
-----BEGIN RSA PUBLIC KEY-----
..Public Key....
-----END RSA PUBLIC KEY-----
EOT;
protected $pri = <<<EOT
-----BEGIN RSA PRIVATE KEY-----
.. Private Key....
-----END RSA PRIVATE KEY-----
EOT;
public function getSignature($data)
{
$signature = null;
$priKey = openssl_pkey_get_private($this->pri);
openssl_sign(iconv('UTF-8', 'UTF-16LE', $data), $signature, $priKey, "sha1WithRSAEncryption");
return base64_encode( $signature );
}
}