我在用PHP的openssl_seal函数加载公钥进行加密时遇到了一些问题…
我已经使用openSSL命令行工具创建了公钥和私钥:
openssl genrsa -des3 -out private.pem 1024
openssl rsa -in private.pem -out public.pem -outform PEM -pubout然而,当我在我的PHP代码中运行它时,我得到了以下错误:
openssl_seal() [function.openssl-seal]: Don't know how to get public key from this private key
openssl_seal() [function.openssl-seal]: not a public key (1th member of pubkeys)当我使用openssl verify public.pem验证公钥时,我得到:
unable to load certificate
1876:error:0906D06C:PEM routines:PEM_read_bio:no start line:.\crypto\pem\pem_lib
.c:648:Expecting: TRUSTED CERTIFICATE有人知道为什么会这样吗?
PHP代码:
public function encrypt($valueToEncrypt, $publicKeyFile)
{
$pk = file_get_contents($publicKeyFile);
$publicKey = openssl_pkey_get_public($pk);
$encrypted = '';
$a_envelope = array();
$a_key = array($publicKey);
if (openssl_seal($valueToEncrypt, $encrypted, $a_envelope, $a_key) === FALSE)
{
while ($msg = openssl_error_string())
echo $msg . "<br />\n";
die('Failed to encrypt data!');
}
openssl_free_key($publicKey);
....发布于 2012-05-15 20:26:46
对于任何遇到同样问题的人来说,这个问题都与在windows上安装xampp有关。在命令行上运行一次全新安装的just php工作得很好。
发布于 2012-07-11 20:49:51
除了StuffandBlah的回答之外:事实上,这与Windows上XAMPP中的OpenSSL版本和Apache中的不同版本有关。下面是如何解决这个问题的a post (复制DLL)。
https://stackoverflow.com/questions/10422268
复制相似问题