Help decrypting in ColdFusion passwords created in .NET
Posted
by KnightStalker
on Stack Overflow
See other posts from Stack Overflow
or by KnightStalker
Published on 2009-10-19T18:03:24Z
Indexed on
2010/04/12
1:03 UTC
Read the original article
Hit count: 375
I have a SQL db storing passwords that were encrypted through a .NET application, that I need to decrypt through a ColdFusion app. I just can't seem to get things set upproperly for the CF decryption to work. Any help would by appreciated. Thanks.
The .NET decryption code is:
public string Decrypt(string input)
{
try
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
int ZeroBasedByteCount = (input.Length / 2);
//Put the input string into the byte array
byte[] inputByteArray = new byte[ZeroBasedByteCount];
int i;
int x;
for (x = 0;x<ZeroBasedByteCount;x++)
{
i = (Convert.ToInt32(input.Substring(x * 2, 2), 16));
inputByteArray[x] = (byte)i;
}
//Create the crypto objects
des.Key = ASCIIEncoding.ASCII.GetBytes(key);
des.IV = ASCIIEncoding.ASCII.GetBytes(key);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
//Flush the data through the crypto stream into the memory stream
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
//Get the decrypted data back from the memory stream
StringBuilder ret = new StringBuilder();
foreach(byte b in ms.ToArray())
{
ret.Append((char)b);
}
return ret.ToString();
}
catch(Exception ex)
{
throw(ex);
return null;
}
}
© Stack Overflow or respective owner