当前位置:   article > 正文

des 加密 解密

public static string desdecrypt(string decryptstring) { byte[] keybytes = en

  1. using System;
  2. using System.Text;
  3. using System.Security.Cryptography;
  4. using System.IO;
  5. public class Des
  6. {
  7. private static string key = "zhoufoxcn";
  8. public string DesEncrypt(string encryptString)
  9. {
  10. byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 8));
  11. byte[] keyIV = keyBytes;
  12. byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
  13. DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
  14. MemoryStream mStream = new MemoryStream();
  15. CryptoStream cStream = new CryptoStream(mStream, provider.CreateEncryptor(keyBytes, keyIV), CryptoStreamMode.Write);
  16. cStream.Write(inputByteArray, 0, inputByteArray.Length);
  17. cStream.FlushFinalBlock();
  18. return Convert.ToBase64String(mStream.ToArray());
  19. }
  20. public static string DesDecrypt(string decryptString)
  21. {
  22. byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 8));
  23. byte[] keyIV = keyBytes;
  24. byte[] inputByteArray = Convert.FromBase64String(decryptString);
  25. DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
  26. MemoryStream mStream = new MemoryStream();
  27. CryptoStream cStream = new CryptoStream(mStream, provider.CreateDecryptor(keyBytes, keyIV), CryptoStreamMode.Write);
  28. cStream.Write(inputByteArray, 0, inputByteArray.Length);
  29. cStream.FlushFinalBlock();
  30. return Encoding.UTF8.GetString(mStream.ToArray());
  31. }
  32. }

转载于:https://www.cnblogs.com/gotolovo/archive/2010/12/04/1896531.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/663617
推荐阅读
相关标签
  

闽ICP备14008679号