I've noticed that Bouncy Castle and OpenSSL is not coded strictly according to PKCS#1 v2.1 RFC, which results in phpseclib not being able to decrypt messages encrypted with the private key. They both set the 2nd-bit to 2 when encrypting with a private key, instead of to 1 !
I have a very simple solution for this: Replace the following line in RSA.php, in the _rsaes_pkcs1_v1_5_decrypt function:
- Code: Select all
if (ord($em[0]) != 0 || ord($em[1]) != 2) {
- Code: Select all
$type = ord($em[1]);
if (ord($em[0]) != 0 || (($type != 1) && ($type != 2))) {
I hope that this would be helpful to others.
Regards,
Chris
* Thanks for the great PHP library. It's definitely one of the best/easiest Cryptography libraries to use that I've came across!
