<?php
$encrypted="lNJ50ODiofcp+adrtAI943HOsjdDTg3UMfUkt0NI7DhUjxCM+NAlBH08WVQRtYK9W8ZoQOta3QH6
PzmJT4WsI0yfNGiUWYgoYgSOtPURSQMbaCt3DM2Y5mEKqzbKLrhN+S+9Jrtmef1VuBUes8wN6rOD
UHxI+vDwQ+utRJRRo9U=";
echo $encrypted."\n";
//私钥解密
$private_key=file_get_contents("rsa_private_key.pem");
$pi_key = openssl_pkey_get_private($private_key);
openssl_private_decrypt(base64_decode($encrypted),$decrypted,$pi_key);
echo "解密后:\n";
echo $decrypted."\n";
执行结果:
lNJ50ODiofcp+adrtAI943HOsjdDTg3UMfUkt0NI7DhUjxCM+NAlBH08WVQRtYK9W8ZoQOta3QH6
PzmJT4WsI0yfNGiUWYgoYgSOtPURSQMbaCt3DM2Y5mEKqzbKLrhN+S+9Jrtmef1VuBUes8wN6rOD
UHxI+vDwQ+utRJRRo9U=
解密后:
taoshihan
java使用公钥加密,php解密:
拿上一步java生成的加密后字符串
<?php
$encrypted="Tt1p5XnamZkkVjGn1cVgEIb7U+CP27Xw93JQQUZyc2Up/rJL4Mx+dA8mxkva1a/I64sUTb7QD//8
gbss4bZY/DHrLityTt2/QjjQUFYD5/Aa1m1QKUBulWY4/C5so5dm6wrRnjolsIFUbY+RfH4B6hp1
taQGBRDum/xEX6OsJ9I=";
echo $encrypted."\n";
//私钥解密
$private_key=file_get_contents("rsa_private_key.pem");
$pi_key = openssl_pkey_get_private($private_key);
openssl_private_decrypt(base64_decode($encrypted),$decrypted,$pi_key);
echo "解密后:\n";
echo $decrypted."\n";
执行结果:
Tt1p5XnamZkkVjGn1cVgEIb7U+CP27Xw93JQQUZyc2Up/rJL4Mx+dA8mxkva1a/I64sUTb7QD//8
gbss4bZY/DHrLityTt2/QjjQUFYD5/Aa1m1QKUBulWY4/C5so5dm6wrRnjolsIFUbY+RfH4B6hp1
taQGBRDum/xEX6OsJ9I=
解密后:
taoshihan
更多OpenSSL相关内容可以查看以下的有用链接: