Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openssl "data greater than mod len"

What does the "data is greater than mod len" error message mean? I have encountered this while trying to decrypt data using php's openssl_private_decrypt. How does one go about solving this issue? Been searching hours online, not getting anywhere.

like image 906
automaton Avatar asked Apr 21 '14 20:04

automaton


3 Answers

Asymmetric RSA keys can encrypt/decrypt only data of limited length i.e. RSAES-PKCS1-v1_5 encryption scheme defined in RFC3447 can operate on messages of length up to k - 11 octets (k is the octet length of the RSA modulus) so if you are using 2048-bit RSA key then maximum length of the plain data to be encrypted is 245 bytes.

like image 153
jariq Avatar answered Oct 03 '22 23:10

jariq


If you are having this decryption error: RSA_EAY_PRIVATE_DECRYPT:data greater than mod len try this command before decrypt your file:

cat yourEncryptedFile| base64 -D > yourEncryptedRawFile
like image 14
Pedro Trujillo Avatar answered Oct 03 '22 23:10

Pedro Trujillo


You can also try openssl enc -in cipherTextFile.base64 -out binaryTextFile.bin -d -a. This was what worked for me when I got this error while trying to decrypt. I was then able to decrypt using openssl rsautl -decrypt -in binaryTextFile.bin -out plainTextFile.txt -inkey my-private-key.pem without failure.

like image 1
Oli Avatar answered Oct 03 '22 23:10

Oli