Re: RijndaelManaged decryption leaves strange characters

From: Alek Davis (alek_xDOTx_davis_xATx_intel_xDOTx_com)
Date: 02/12/04


Date: Thu, 12 Feb 2004 10:23:22 -0800

David,

When you convert the array of decrypted bytes to string, make sure that you
only include the number of actually decrypted bytes, not the whole array. I
don't know how you do this, but a typical problem is that when you allocate
an array of bytes to hold decrypted data, you do not know in advance what
the size of this array should be (since encrypted data are longer than plain
text for Rijndael). So acceptable practice is to allocate the array of the
same size as encrypted array, but when the decryption is done and you know
how many plain text bytes were returned, only convert these bytes to string.

Alek

"dm_dal" <REMOVE_THIS.dmy75252@yahoo.com> wrote in message
news:OZHKGrY8DHA.2924@tk2msftngp13.phx.gbl...
> We've got an encryption/decryption assembly that we built in-house that
uses
> the RijndaelManaged to encrypt/decrypt certain pieces of sensative data
that
> is stored in a SQL Server 2K database.
>
> Basically here's the flow:
>
> Encrypt:
> Encrypt the data using RijndaelManaged in CBC Mode.
> Store the Base64Encoded cipher text in the DB (column is varchar(80))
>
> Decrypt:
> Pull Base64Encoded string from DB and Convert.FromBase64String
> Decrypt using RijndaelManaged in CBC Mode
> return Encoding.UTF8.GetString( unencrypted byte[] );
>
> When viewing the decrypted text in a web form, the display is correct.
> However, when viewed in a WindowsForm DataGrid, the decrypted string is
> shown with trailing "|||||||" characters. When you click in the cell to
> edit the text, the trailing characters disappear, when you leave the cell,
> they reappear. If you actually do an edit on the cells data, the trailing
> characters disappear and don't return when you leave the cell.
>
> Do you suppose this extra character data is the result of the UTF8
encoding?
>
> David
>
>



Relevant Pages

  • RE: Using Win32 CryptDecrypt to Decrypt RijndaelManaged
    ... I figured out how to use RijndaelManaged with AES in the C++ app. ... C++ crypto WILL successfully decrypt the .NET generated ... I am trying to write a Win32 app that can decrypt that string using the ... I can get both to encrypt and decrypt successfully in their own projects, ...
    (microsoft.public.platformsdk.security)
  • Re: Encrypt and Decrypt a file using .NET 2.0?
    ... public static string GenerateKey() ... DES des = DES.Create; ... // Distribute this key to the user who will decrypt this file. ... // Get the Key for the file to Encrypt. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: .NET Crypto Classes Interoperability with Win32 Crypto APIs
    ... >the hash of the string you are feeding in. ... when i encrypt a string using .NET classes and try ... >> decrypt it using Win32 APIs, ...
    (microsoft.public.dotnet.security)
  • Re: Encrypt and Decrypt a file using .NET 2.0?
    ... public static string GenerateKey() ... using (CryptoStream cryptoStream = new CryptoStream(outFile, ... // Distribute this key to the user who will decrypt this file. ... // Get the Key for the file to Encrypt. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Decryptionfailed to bring original text back....
    ... cryptography, but now using them on web.config, any idea, I like to ... There isn't really much reason to encrypt a .NET string with ... what happen when you decrypt the encrypted ...
    (microsoft.public.dotnet.security)