DecodeEncrypt.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Security.Cryptography;
  6. using System.IO;
  7. namespace ETD.Frame
  8. {
  9. public class DecodeEncrypt
  10. {
  11. #region ========解密========
  12. /// <summary>
  13. /// 解密
  14. /// </summary>
  15. /// <param name="Text"></param>
  16. /// <returns></returns>
  17. public static string Decrypt(string Text)
  18. {
  19. return Decrypt(Text, "jijianguo");
  20. }
  21. /// <summary>
  22. /// 解密数据
  23. /// </summary>
  24. /// <param name="Text"></param>
  25. /// <param name="sKey"></param>
  26. /// <returns></returns>
  27. public static string Decrypt(string Text, string sKey)
  28. {
  29. DESCryptoServiceProvider des = new DESCryptoServiceProvider();
  30. int len;
  31. len = Text.Length / 2;
  32. byte[] inputByteArray = new byte[len];
  33. int x, i;
  34. for (x = 0; x < len; x++)
  35. {
  36. i = Convert.ToInt32(Text.Substring(x * 2, 2), 16);
  37. inputByteArray[x] = (byte)i;
  38. }
  39. des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
  40. des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
  41. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  42. CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
  43. cs.Write(inputByteArray, 0, inputByteArray.Length);
  44. cs.FlushFinalBlock();
  45. return Encoding.Default.GetString(ms.ToArray());
  46. }
  47. #endregion
  48. }
  49. }