S
-Steve-
I'm being passed a string that has been encrypted using 3DES. I'm writing a
function to decrypt that string.
All is well except I get garbarage before the decrypted string I'm supposed
to be retrieving.
For example I should get back 12345678, but instead I'm getting back
?l???#?K12345678 (everything before the real string is random though)
Anything jump out at anybody on what I should be doing?
Here is the function (that I stole of the web by the way) I'm using to
decrypt the string:
byte[] arrToDecrypt = Convert.FromBase64String(strToDecrypt);
// Create Key and IV
byte[] tdesKey = ASCIIEncoding.ASCII.GetBytes(key);
byte[] tdesIV = Encoding.ASCII.GetBytes(strToDecrypt.Substring(0, 8));
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Mode = CipherMode.CBC;
tdes.Padding = PaddingMode.PKCS7;
MemoryStream ms = new MemoryStream(arrToDecrypt);
CryptoStream decStream =
new CryptoStream(ms, tdes.CreateDecryptor(tdesKey, tdesIV),
CryptoStreamMode.Read);
StreamReader sr = new StreamReader(decStream, Encoding.ASCII);
return sr.ReadToEnd();
function to decrypt that string.
All is well except I get garbarage before the decrypted string I'm supposed
to be retrieving.
For example I should get back 12345678, but instead I'm getting back
?l???#?K12345678 (everything before the real string is random though)
Anything jump out at anybody on what I should be doing?
Here is the function (that I stole of the web by the way) I'm using to
decrypt the string:
byte[] arrToDecrypt = Convert.FromBase64String(strToDecrypt);
// Create Key and IV
byte[] tdesKey = ASCIIEncoding.ASCII.GetBytes(key);
byte[] tdesIV = Encoding.ASCII.GetBytes(strToDecrypt.Substring(0, 8));
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Mode = CipherMode.CBC;
tdes.Padding = PaddingMode.PKCS7;
MemoryStream ms = new MemoryStream(arrToDecrypt);
CryptoStream decStream =
new CryptoStream(ms, tdes.CreateDecryptor(tdesKey, tdesIV),
CryptoStreamMode.Read);
StreamReader sr = new StreamReader(decStream, Encoding.ASCII);
return sr.ReadToEnd();