Decrypt problem using Rijndael
- From: "Jeffrey Ah-Chong" <jahchong@xxxxxxxxxxxxxx>
- Date: Fri, 21 Apr 2006 10:07:01 +0400
Hi guys
I'm using an algo to encrypt/decrypt an xml file using Rijndael. However, SOMETIMES (yea that's right, it does not happen all the time) the decrypt algo fails when I try to read the data in cryptostream:
'Read the data out of the crypto stream.
csDecrypt.Read(btOriginalData, 0, btOriginalData.Length)
with the System.Security.Cryptography.CryptographicException "Length of the data to decrypt is invalid"
I've spent hours unsuccessfully trying to know what's the problem. Everything seems ok. Here's the code snippet for decrypt. Can anyone help please?
' Retrieves Key, IV, and data from encrypted file
srKeyFile = New System.IO.StreamReader(DecryptKeyFile, System.Text.Encoding.Unicode)
sKey = srKeyFile.ReadLine()
sKeyByte = EncUnicode.GetBytes(sKey)
sIV = srKeyFile.ReadLine()
sIVByte = EncUnicode.GetBytes(sIV)
sData = srKeyFile.ReadLine()
sDataByte = EncUnicode.GetBytes(sData)
'Get a decryptor that uses the same key and IV as the encryptor.
objDecryptor = myRijndael.CreateDecryptor(sKeyByte, sIVByte)
'Now decrypt the previously encrypted message using the decryptor obtained.
msDecrypt = New System.IO.MemoryStream(sDataByte)
csDecrypt = New System.Security.Cryptography.CryptoStream(msDecrypt, objDecryptor, _
System.Security.Cryptography.CryptoStreamMode.Read)
btOriginalData = New Byte(sDataByte.Length) {}
'Read the data out of the crypto stream. EXCEPTION ON THIS LINE
csDecrypt.Read(btOriginalData, 0, btOriginalData.Length)
'Convert the byte array back into a string.
sXML = EncASCII.GetString(btOriginalData).Replace("&", "&")
Thanks
Jeffrey
.
- Follow-Ups:
- Re: Decrypt problem using Rijndael
- From: Joe Kaplan \(MVP - ADSI\)
- Re: Decrypt problem using Rijndael
- From: Dominick Baier [DevelopMentor]
- Re: Decrypt problem using Rijndael
- Prev by Date: SSL with .NET 1.1
- Next by Date: "Security Adjustment wizard" broken, .net 1.1
- Previous by thread: SSL with .NET 1.1
- Next by thread: Re: Decrypt problem using Rijndael
- Index(es):
Relevant Pages
|