Hi I would like to know why RSA can be performed (encrypt/decrypt) with only one public key in phpseclib?
$rsa is an instance of phpseclib/Crypt/RSA.php (link: https://github.com/phpseclib/phpseclib/blob/master/phpseclib/Crypt/RSA.php) $publicKey keys here are the same.
function encryptData($data, $publicKey) {
$rsa = new Crypt_RSA();
$rsa->loadKey($publicKey); // public key
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$output = $rsa->encrypt($data);
return base64_encode($output);
}
function decryptData($data, $publicKey) {
$rsa = new Crypt_RSA();
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$ciphertext = base64_decode($data);
$rsa->loadKey($publicKey); // public key
$output = $rsa->decrypt($ciphertext);
// $output = $rsa->decrypt($data);
I don't understand why the above code works. And for the same reason, I can't implement it in Ruby which requires a key pair for such operation. Any help would be appreciate.
$publicKeydoesn't mean it's a public key.