I have a string that's encrypted using some crypto classes in Java (RSA/ECB/PKCS1Padding) and a public key we exchanged in advance.
I want to decrypt that string using our private key and this is the code I have.
X509Certificate2 cert = new X509Certificate2("c:\\test.pfx", "test");
string s = "very long encrypted data";
RSACryptoServiceProvider privateKeyProvider = (RSACryptoServiceProvider)cert.PrivateKey;
string decryptedTest = System.Text.Encoding.UTF8.GetString(privateKeyProvider.Decrypt(Convert.FromBase64String(s), true));
I get an exception with error message.
"System.Security.Cryptography.CryptographicException: Error occurred while decoding OAEP padding"
What is that I'm doing wrong?
Call Decrypt
with the second parameter set to false
.
MSDN
...false to use PKCS#1 v1.5 padding.