【发布时间】:2013-09-21 10:51:03
【问题描述】:
$publicKey = "../ssh/public/pub"; $plaintext = "要加密的字符串";
$pubKey = openssl_pkey_get_public($publicKey);
openssl_public_encrypt($plaintext, $encrypted, $pubKey);
echo $encrypted; //encrypted string
以上代码生成以下错误
openssl_public_encrypt() [http://php.net/function.openssl-public-encrypt]:密钥参数不是有效的公钥 [APP/controllers/supportservice_controller.php,第 144 行]
我使用 openssl 创建了密钥:
生成一个 1024 位 rsa 私钥,要求输入密码以对其进行加密并保存到文件 openssl genrsa -des3 -out /path/to/privatekey 1024
为私钥生成公钥并保存到文件
openssl rsa -in /path/to/privatekey -pubout -out /path/to/publickey
【问题讨论】:
标签: php encryption openssl public-key-encryption php-openssl