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

Udi*_*sio 5 php openssl rsa encryption-asymmetric private-key

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

谢谢!

小智 5

试试phpseclib,一个纯PHP RSA实现:

<?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;
?>
Run Code Online (Sandbox Code Playgroud)

安全警告:如果您要使用phpseclib,请确保遵循RSA加密的最佳做法.有关更多详细信息和替代方法,请参阅此答案.


pro*_*php 3

openssl aes-256-cbc -a -salt -in inputfile.txt -out encryptedfile.txt -pass pass:thepassword
openssl aes-256-cbc -d -a -in encryptedfile.txt -out decryptedfile.txt 
Run Code Online (Sandbox Code Playgroud)

可以执行这些,并且应该能够根据需要更改密码。

  • 郑重声明:服务器上的任何用户都可以解析正在运行的程序的命令行,通过命令行提供密码进行任何操作,但使用虚拟数据进行本地测试是一个坏主意。 (3认同)