locked
Problem decrypting... RRS feed

  • Question

  • User-563116531 posted

    Hi all

     I am using the following code to encrypt and decrypt a string, which I store in a sql server database as a varchar field in between.

    string accountNumber = Cryptographer.EncryptSymmetric("RijndaelManaged", txtAccountNumber.Text); 
    
    // In between I store in a DB, and load using
    // accountNumber  = dr["accountNumber "].ToString();
    //
    //--------------------------------------------
    
    txtAccountNumber.Text = Cryptographer.DecryptSymmetric("RijndaelManaged", accountNumber );
     

    However when I try and decrypt it I get the following error...

    Invalid length for a Base-64 char array.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.FormatException: Invalid length for a Base-64 char array.

     

    PLEASE HELP!!

     

    Monday, February 11, 2008 8:32 AM

Answers

  • User-2005691517 posted

     This could happen if the encrypted string gets truncated due to some reason (e.g. insuffficient database field length).

    Debug and verify that the encrypted string you are storing and the string you are trying to decrypt are the same.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 11, 2008 9:03 AM

All replies

  • User-2005691517 posted

     This could happen if the encrypted string gets truncated due to some reason (e.g. insuffficient database field length).

    Debug and verify that the encrypted string you are storing and the string you are trying to decrypt are the same.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 11, 2008 9:03 AM
  • User-5434633 posted

    Hi,

     

    Change your lines as following.

    string accountNumber = Uri.EscapeDataString(Cryptographer.EncryptSymmetric("RijndaelManaged", txtAccountNumber.Text));

    txtAccountNumber.Text = Cryptographer.DecryptSymmetric("RijndaelManaged", Uri.UnescapeDataString(accountNumber) ); 

    Thursday, July 22, 2010 11:57 PM