Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decryption error and strange symbols #1320

Open
unholyHub opened this issue Nov 28, 2018 · 4 comments

Comments

@unholyHub
Copy link

commented Nov 28, 2018

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\prim41ws\vendor\phpseclib\phpseclib\phpseclib\Crypt\RSA.php on line 2553

Mode:
$rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);
Result:
Notice: Decryption error in C:\xampp\htdocs\prim41ws\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�|"

@terrafrost

This comment has been minimized.

Copy link
Member

commented Nov 30, 2018

It'd help to know how you generated your ciphertext. Did you use OpenSSL? phpseclib? Do you know?

That said, the reason it's failing with PKCS1 / OAEP is because the ciphertext is 65 bytes long whereas the modulo is 64 bytes long (512 bits).

@terrafrost

This comment has been minimized.

Copy link
Member

commented Dec 1, 2018

It looks like this question was cross posted on stackoverflow FWIW:

https://stackoverflow.com/questions/53555168/rsa-decryption-with-phpseclib-is-failing

@unholyHub

This comment has been minimized.

Copy link
Author

commented Dec 1, 2018

Don't bash me for that I want some help from other places.

@terrafrost

This comment has been minimized.

Copy link
Member

commented Dec 2, 2018

I wasn't bashing you lol. I was just posting the link because if you got the answer there there's not a lot of need for me or anyone else to spin our wheels here.

An answer is an answer regardless of where you get it from so if you get an answer on stackoverflow the need to post the answer here is lessened. I suppose there might also be some virtue to copy / pasting the answer from stackoverflow to here but idk lol.

But I wasn't bashing you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.