C# equivalent to this ColdFusion Decrypt function

天大地大妈咪最大 提交于 2020-02-02 10:18:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!