Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Security.Cryptography.CryptographicException: 'Cryptography_OAEPDecoding'

i have a program that has to decrypt 3 phrases using a RSA privateKey but keeps showing that exception above, System.Security.Cryptography.CryptographicException: 'Cryptography_OAEPDecoding', what do i need to change for it to work?, i've tried seeing other pages but its too confusing, and i end up adding too many commented code and starting again.

Exception that pops

like image 591
Sergio Avatar asked Oct 15 '25 11:10

Sergio


1 Answers

The error occurs because you explicitly tell the RSA crypto service provider to use OAEP padding but your ciphers are encrypted using PKCS1 padding.

// Your current statement:
var decryptedBytes = rsa.Decrypt(resultBytes, true);

The second parameter (fOAEP is documented like:

//   fOAEP:
//     true to perform direct System.Security.Cryptography.RSA decryption using
//     OAEP padding (only available on a computer running Microsoft Windows XP or
//     later); otherwise, false to use PKCS#1 v1.5 padding.

So by just changing to false;

var decryptedBytes = rsa.Decrypt(resultBytes, false);

We get the following output:

INICIO DE LA SEGUNDA PARTE
M A N D A   C O R R E O   A   J A V I E R   B E L
C O N   T U   N O M B R E   C O M P L E T O
Y   L A   F E C H A / H O R A

Important side note:

Probably while copy/pasting, your base64 ciphers are incorrect. I corrected them like this:

var FRASE1 = "IlmhPFKroDuK4AUtBGfaf5J6791DzMenkUBEXfRwZ7rmBHswHTf02LAba/Hs+rsh3wL6dpMQlEhlaIAVHaZZsw==";
var FRASE2 = "AMbsYR1pq9WYUj3mdqKvJj7tMznqBAcZLxM2C6WzNEUOqKD/qdEE76bNJPmYFKwVei2rhuHFsxh7nUzXmVKRdw==";
var FRASE3 = "J1jnq551phV+W4MVzE5caXIHqM3E0gz/t9PVtorqvDVqfne8CCF9UQiEk33Rssi1IEz6JH8Fd8ZAvnX3UWe5Vw==";
like image 197
Oguz Ozgul Avatar answered Oct 18 '25 03:10

Oguz Ozgul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!