使用私钥和PKCS1进行PHP RSA加密

我需要使用RSA,PKCS1,私钥和PHP加密字符串.我甚至找不到可以与exec()一起使用的终端命令.有谁知道怎么做?

谢谢!

最佳答案
试试phpseclib, a pure PHP RSA implementation

<?php
include('Crypt/RSA.php');

$rsa = new Crypt_RSA();
//extract($rsa->createKey());

$plaintext = 'terrafrost';

$rsa->loadKey($privatekey);
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$ciphertext = $rsa->encrypt($plaintext);

echo $plaintext;
?>

Security warning: If you’re going to use phpseclib, make sure you 07001. See also 07002 for more details and an alternative approach.

转载注明原文:使用私钥和PKCS1进行PHP RSA加密 - 代码日志