I am rewriting an internal Coldfusion app that stores passwords in the database using Encrypt and Decrypt into C#. My Coldfusion code is using two parameters like this:
<cfset strDecrypted = decrypt(ToString(toBinary(strBase64Value)),"keycode") />
Where strDecrypted is the decrypted string returned, strBase64Value is the encrypted string in the database and "keycode" is an arbitrary key string I came up with so I don't disclose the real key here. My C# code sample is below, I get an error when I pass in the key. The error message says "The specified key is not a valid size for this algorithm. Parameter name: key"
private string ConvertString(string string1, string string2)
{
byte[] key = ASCIIEncoding.ASCII.GetBytes(string1);
byte[] encryptedData = Convert.FromBase64String(string2);
Aes aes = Aes.Create();
aes.Mode = CipherMode.ECB;
using (var ms = new MemoryStream())
{
using (var cs = new CryptoStream(ms, aes.CreateDecryptor(key, null), CryptoStreamMode.Write))
{
cs.Write(encryptedData, 0, encryptedData.Length);
}
byte[] decryptedData = ms.ToArray();
string clearText = Encoding.ASCII.GetString(decryptedData);
return clearText;
}
}
I'm not sure if I should post here in the Coldfusion forums or the C# forums, so I'll start here first.
Thanks,
Rick