zoukankan      html  css  js  c++  java
  • C#中MD5加密

     1 using System.Security.Cryptography;
     2 using System.Text;
     3 
     4 namespace Common
     5 {
     6     public class Md5Helper
     7     {
     8         public string GetMd5(string txt)
     9         {
    10             //创建md5对象
    11             MD5 md5 = MD5.Create();
    12             //将字符串转成字节数组
    13             byte[] bs = Encoding.UTF8.GetBytes(txt);
    14             //加密
    15             byte[] bs2 = md5.ComputeHash(bs);
    16             //将字节数组转成字符串
    17             StringBuilder sb = new StringBuilder();
    18             for (int i = 0; i < bs2.Length; i++)
    19             {
    20                 sb.Append(bs2[i].ToString("X2")); //x小写X大写
    21             }
    22             return sb.ToString();
    23         }
    24     }
    25 }
  • 相关阅读:
    JZ-C-36
    JZ-C-35
    JZ-C-34
    JZ-C-33
    JZ-C-32
    JZ-C-31
    JZ-C-30
    JZ-C-29
    JZ-C-28
    JZ-C-27
  • 原文地址:https://www.cnblogs.com/Liqiongyu/p/5083072.html
Copyright © 2011-2022 走看看