0

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?

1
  • In which line do you get the exception? Commented Dec 19, 2011 at 19:05

2 Answers 2

0

Call Decrypt with the second parameter set to false. MSDN

...false to use PKCS#1 v1.5 padding.

Sign up to request clarification or add additional context in comments.

1 Comment

I figured it out but, I will give you the credit. I appreciate your time.
0

This is the working code.

 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));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.