Click here to Skip to main content
15,891,694 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am able to encrypt successfully but am unable to decrypt it.
My code goes like this:
C#
public string DecryptRSA(string data, string privatestring)
    {
        string rsaprivate = System.Web.HttpContext.Current.Server.MapPath(privatestring);
        string clearData = null;
      //  try
       // {
            CspParameters param = new CspParameters();
            param.Flags = CspProviderFlags.UseMachineKeyStore;
            RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(param);

            //string merchantRsaPublic = GetXmlRsaKey(rsaprivate);
            StreamReader reader = new StreamReader(rsaprivate);
            string privatekeyXml = reader.ReadToEnd();
            rsaProvider.FromXmlString(privatekeyXml);
            byte[] asciiString = Encoding.ASCII.GetBytes(data);

           #1 byte[] decryptedData = rsaProvider.Decrypt(asciiString, true);
            string resultString = Convert.ToBase64String(decryptedData);

           // clearData = Convert.ToString(decryptedData);
       // }
       //catch (CryptographicException ex)
       // {
            Console.Write("asasa");
            //Log.Error("A cryptographic error occured trying to decrypt a value for " + privatestring, ex);

       //}
        return resultString;
    }

Now, with the try catch block there is no runtime error and the desired ouput is also received.
However with debugging & no try catch block the line #1 gives a error which says:
"The data to be decrypted exceeds the maximum for this modulus of 256 bytes."-> I have knowledge about this but don't know, how to solve this error. What would be the right code?

Please help.
Posted
Updated 12-Feb-11 19:36pm
v2

1 solution

Have a look at these discussions, they look similar:
Link 1[^]
Link 2[^]

Error reported has been faced by quite a lot of people. Google for more, if needed.
 
Share this answer
 
Comments
Supratik sadhuka 13-Feb-11 2:02am    
Thanx for the links...Every page in google search has been made...butd solution is hard reached...decyption alone is making my project incomplete...
Sandeep Mewara 13-Feb-11 2:14am    
Oh! Ok. Lets see then if some experts here can help. All the best.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900