RSA encryption and decryption, no padding in PHP
Problem:
in PHP 5.3 Is there a class that provides RSA encryption/decryption without padding? I have the private and public keys, p, q and modulus ready.
Answer:
You can use phpseclib, a pure PHP RSA implementation:
<?php include('Crypt/RSA.php'); $privatekey = file_get_contents('private.key'); $rsa = new Crypt_RSA(); $rsa->loadKey($privatekey); $plaintext = new Math_BigInteger('aaaaaa'); echo $rsa->_exponentiate($plaintext)->toBytes(); ?>
phpseclib allows you to specify that plaintext and ciphertext should be used The padding type. In this case, we are not using padding, so we pass a Math_BigInteger object instead of a string.
The above is the detailed content of Is There a PHP 5.3 Class for Unpadded RSA Encryption/Decryption?. For more information, please follow other related articles on the PHP Chinese website!