Re: Decrypt problem using Rijndael
- From: Dominick Baier [DevelopMentor] <dbaier@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 21 Apr 2006 14:10:31 +0000 (UTC)
you cannot use Unicode to convert between bytes and strings - replace all the conversions with Convert.From/To Base64String
---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com
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
.
- References:
- Decrypt problem using Rijndael
- From: Jeffrey Ah-Chong
- Decrypt problem using Rijndael
- Prev by Date: Re: UNC logins with VB.NET
- Next by Date: Re: How to access shared folder with different credentials?
- Previous by thread: Decrypt problem using Rijndael
- Next by thread: Re: Decrypt problem using Rijndael
- Index(es):
Relevant Pages
|