Note that there are some explanatory texts on larger screens.

plurals
  1. POError occurred while decoding OAEP padding
    primarykey
    data
    text
    <p>While decrypting text using <code>RSACryptoServiceProvider.Decrypt</code>, I am getting the error:</p> <blockquote> <p>Error occurred while decoding OAEP padding.</p> </blockquote> <p>Here's my code:</p> <pre><code>CspParameters cspParam = new CspParameters(); cspParam = new CspParameters(); cspParam.Flags = CspProviderFlags.UseMachineKeyStore; clsCertificates cc = new clsCertificates(); string a = ""; cc.OpenStoreIE(ref a); cc.SetProperties(); X509Certificate2 cert = new X509Certificate2(); cert = cc.x509_2Cert; RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspParam); //to gentrate private and public keys from the certificate rsa.FromXmlString(cert.PublicKey.Key.ToXmlString(false)); String publicKey = rsa.ToXmlString(false); // gets the public key String privateKey = rsa.ToXmlString(true); // gets the private key working if paramter is false if true give error key is not valid for use in specified state Response.Write("&lt;Textarea rows=10 cols=100&gt;PUBLIC: " + publicKey + "&lt;/TextArea&gt;"); Response.Write("&lt;Textarea rows=10 cols=100&gt;PRIVATE: " + privateKey + "&lt;/Textarea&gt;"); Response.Write("&lt;BR&gt;Encrypting the string \"HelloThere\" with the public Key:&lt;BR&gt;"); String str = "HelloThere"; RSACryptoServiceProvider RSA2 = new RSACryptoServiceProvider(cspParam); //---Load the Public key--- RSA2.FromXmlString(publicKey); //working with the folowing line instead of above but i need the keys of he certificte //RSA2.ToXmlString(true); Byte[] EncryptedStrAsByt = RSA2.Encrypt(System.Text.Encoding.Unicode.GetBytes(str), true); String EncryptedStr = System.Text.Encoding.Unicode.GetString(EncryptedStrAsByt); Response.Write("&lt;Textarea rows=10 cols=100&gt;Encrypted String: " + EncryptedStr + "&lt;/Textarea&gt;"); Response.Write("&lt;BR&gt;Decrypting the Encrypted String with the Private key:&lt;BR&gt;"); RSACryptoServiceProvider RSA3 = new RSACryptoServiceProvider(cspParam); //---Load the Private key--- RSA3.FromXmlString(privateKey); //working with the folowing line instead of above but i need the keys of he certificte //RSA3.ToXmlString(true); Byte[] DecryptedStrAsByt = RSA3.Decrypt(EncryptedStrAsByt, true );//Error if true then error is error occured while decoding the OAE$P padding and if false then error is bad key i am using windows xp so it should be true. String DecryptedStr = System.Text.Encoding.Unicode.GetString(DecryptedStrAsByt); Response.Write("&lt;Textarea rows=10 cols=100&gt;Decrypted String: " + DecryptedStr + "&lt;/Textarea&gt;"); </code></pre> <p>The above is works if I am not using the keys of my digital certificate. but if the keys are from the digital certificate, I get the OAEP padding error.</p> <p>Note: This question is in continuation of the <a href="https://stackoverflow.com/questions/949907/error-occurred-while-decoding-oaep-padding">Error occurred while decoding OAEP padding</a> question</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload