问题
I have a function in ColdFusion that encrypts and decrypts passwords. I need someone to look at the function and point me to or write me a c# equivalent. It is needed for a project asap so I can throw you some cash through paypal if you can help.
CF function:
Decrypt("CLbtkjNkcofJ5D8s4Ri7nA==", "EajmplPP8DHg6Tqq8BVRMw==", "AES", "Base64")
This is the real function, with real data from a test side, that needs to be converted.
Any help would be awesome .. and profitable.
Thanks, Donnie
回答1:
Your starting point would be System.Security.Cryptography.Aes
But these things can get quite hairy, for example you need to know which mode to use. Since your example is not showing an IV (initialization vector) you should use CipherMode.ECB.
Here is some test code, I will leave it to you to wrap this up in a nice re-usable function
byte[] key = Convert.FromBase64String("EajmplPP8DHg6Tqq8BVRMw==");
byte[] encryptedData = Convert.FromBase64String("CLbtkjNkcofJ5D8s4Ri7nA==");
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);
Console.WriteLine(clearText);
}
The answer => "AccessOne"
来源:https://stackoverflow.com/questions/6396464/c-sharp-equivalent-to-this-coldfusion-decrypt-function