A Few Comments.
-
You may find this page helpful:
http://phpseclib.sourceforge.net/interop.html#rsaencpkcs1,p1phpseclib,p2openssl
-
I had suggested in my earlier answer that you do
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
. Your latest edited post still does not have you doing that:$rsa->loadKey($public_key); // public key $plaintext = '...'; $ciphertext = $rsa->encrypt($plaintext); file_put_contents("ciphertext.txt",$ciphertext);
Doing
define('CRYPT_RSA_PKCS15_COMPAT', true);
only does anything if you're in PKCS1 mode and you're not. You're post says you're doing
openssl rsautl -decrypt -inkey private.pem
. idk how the wholexxd
command is supposed to work but normally, with OpenSSL, you need to specify an input file by doing-in ciphertext.txt
, which you're not doing.
Working Code
Using your public and private key this worked for me:
<?php
include('Crypt/RSA.php');
$rsa = new Crypt_RSA();
$public_key = '-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDGCglgIcCG5a8xlZHEDRtQQTc4
kfxENNBtVN8bE4errA06mJ10WavP2Hg+k11NQip71IQPfIF9jlk1CsqT5ZHXOrOq
RmufHFLa3fiuPvFiMB1NjK4F28Gk4LwyZrfTWc2V6S0xpL5XkFeWRW6I69xckOXj
GqkC5dsWv/IlvPeVbwIDAQAB
-----END PUBLIC KEY-----';
$rsa->loadKey($public_key); // public key
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$plaintext = '...';
$ciphertext = $rsa->encrypt($plaintext);
file_put_contents("ciphertext.txt",$ciphertext);
...and on the CLI:
openssl rsautl -decrypt -inkey private.pem -in ciphertext.txt
Here's the output I got:
...