Encrypt and Decrypt text with RSA in PHP

mic-kul picture mic-kul · Dec 19, 2010 · Viewed 127.1k times · Source

Is there any class for PHP 5.3 that provides RSA encryption/decryption without padding?

I've got private and public key, p,q, and modulus.

Answer

user530167 picture user530167 · Dec 26, 2010

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();
?>