I have mobile application that encrypts strings with RSA and sends that encrypted data to PHP web server.
After a search I found that phpseclib is used to decrypt RSA Latest version 2.0.
No matter what I do I receive despite error despite used mode
Am i doing something wrong?
What I have tried:
Private key for decryption:
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBAJyHUgC1ijhsETeuoNMh4c4yrFoL4juL/yDderMC9fBd1TFgEoJ5dxzMzdlzVVj7Vc/H/I+k13yY3W0MknS//k8CAwEAAQJAaaL1l57s8lkUYZTL2tFh9+vA32BnxLIdc0ullAwqeJV21wXcEyDA67fbmBywdt+pVKkeO2NU7fD3e+DZREuJ0QIhAPZNo9jirkRl4i/Lv3jWt6SmeUBeyIKK0u4lZiBF9KAZAiEAorDjj2c9WBdP46S9hK7yj0U5/0QHB0pO01j9QSVBvqcCIQDrYre7hqdU5qmLVATgzxMiX5ZxViP53gJHZaZ8IV7vwQIgTTYEGafWjjsqGBC0PQdGaMZi+wnPCB+0/0rpjoRfClsCIBPzZw+lappnVxXHuUoQQeN6uevqSvmgvC42UyA4HABa
-----END RSA PRIVATE KEY-----
Encrypted message (base64 encoded):
SMZiVTAMizngWa5Yg2Xp0F3Coy4cIsLB6mru2rLhxnvS2SC\/rm9pgPVLdA\/hp+1TIbzHZqjc2lnP\nkvzh797WlA==\n
PHP sample code:
$rsa = new RSA();
$rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1);
$rsa->loadKey($privateKey);
echo $rsa->decrypt(base64_decode($strBase64));
Result:
Notice: Decryption error in C:\xampp\htdocs\webservice\vendor\phpseclib\phpseclib\phpseclib\Crypt\RSA.php on line 2553
Mode:
$rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);
Result:
Notice: Decryption error in C:\xampp\htdocs\webservice\vendor\phpseclib\phpseclib\phpseclib\Crypt\RSA.php on line 2432
Mode:
$rsa->setEncryptionMode(RSA::ENCRYPTION_NONE);
Result:
string(128) "I�W��B'q����;k��}�1������=��x���*���_��aq�)�D� '�m{��� ��n���C:��t �E����R=�S�y�3$QC�EV.3C�{�.Y�jx�6��!�e�˱]�I ����S�/�'I�|"
openssl rsautl -decrypt -in encrypted.txt -out plaintext.txt -raw -inkey priv.pemvia the CLI and got a "data greater than mod len" back. This makes sense because the ciphertext is 65 bytes long whereas the modulo for the key is 64 bytes long (512 bits)SMZiVTAMizngWa5Yg2Xp0F3Coy4cIsLB6mru2rLhxnvS2SC/rm9pgPVLdA/hp+1TIbzHZqjc2lnPkvzh797WlA==