Having problem with Cryptography

Last post 11-13-2009 11:56 AM by TATWORTH. 2 replies.

Sort Posts:

  • Having problem with Cryptography

    11-13-2009, 10:57 AM
    • Member
      56 point Member
    • kem06.net
    • Member since 12-11-2007, 7:58 AM
    • Posts 306

     When i attempt to decrypto my string i get the following error:

    System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Security.Cryptography.CryptographicException: Length of the data to decrypt is invalid.

    at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)

    The code i try is:

     System.IO.MemoryStream ms = new System.IO.MemoryStream(encryptedcryptData.Bytes, 0, encryptedcryptData.Bytes.Length);
                byte[] b = new byte[encryptedcryptData.Bytes.Length - 1 + 1];
    
                ValidateKeyAndIv(false);
                CryptoStream cs = new CryptoStream(ms, _crypto.CreateDecryptor(), CryptoStreamMode.Read);
    
                try
                {
                    cs.Read(b, 0, encryptedcryptData.Bytes.Length - 1);
                }
                catch (CryptographicException ex)
                {
                    throw new CryptographicException("Unable to decrypt cryptData. The provided key may be invalid.", ex);
                }
                finally
                {
                    cs.Close();
                }
                return new cryptData(b);


     

    How can i get rid of this error. Thank sin advance...

  • Re: Having problem with Cryptography

    11-13-2009, 11:02 AM
    • Participant
      1,597 point Participant
    • vishwaraj1
    • Member since 11-07-2008, 7:44 PM
    • India
    • Posts 422

    try this link... Hope this can solve your problem...
    http://forums.asp.net/t/1491121.aspx




    Regards:

    Vishwaraj Malik

    VB to C# Converter


    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: Having problem with Cryptography

    11-13-2009, 11:56 AM
    • All-Star
      62,543 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 8:34 AM
    • England
    • Posts 12,210
    • TrustedFriends-MVPs

    For some encrypt/decrypt routines, please look at CommonEncrypt.cs in the CommonCS project in the CommonData solution at http://commondata.codeplex.com/Thread/View.aspx?ThreadId=26395

    These routines will encrypt/decrypt and come with unit tests to validate them.

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Page 1 of 1 (3 items)