TmdCrypt.cs 1.0 KB

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5. namespace TEAMModelOS.SDK.Helper.Security.TmdCrypt
  6. {
  7. public static class TmdCrypt
  8. {
  9. private static string DoSHA256AndBase64(string password)
  10. {
  11. SHA256 sha256 = new SHA256CryptoServiceProvider();//建立一個SHA256
  12. byte[] source = Encoding.Default.GetBytes(password);//將字串轉為Byte[]
  13. byte[] crypto = sha256.ComputeHash(source);//進行SHA256加密
  14. string resultSha256 = Convert.ToBase64String(crypto);
  15. sha256.Dispose();
  16. return resultSha256;
  17. }
  18. /// <summary>
  19. /// TMD密码加密
  20. /// </summary>
  21. /// <param name="password"></param>
  22. /// <returns></returns>
  23. public static string Encrypt(string password) {
  24. return DoSHA256AndBase64(DoSHA256AndBase64(DoSHA256AndBase64(password) + DoSHA256AndBase64(password)) + DoSHA256AndBase64(password));
  25. }
  26. }
  27. }