You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
693 B
C#

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Security.Cryptography;
using System.Text;
namespace Common.Helpers
{
public class Md5
{
public static string Encrypt(string str)
{
string pwd = string.Empty;
MD5 md5 = MD5.Create();
// 编码UTF8/Unicode 
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
// 转换成字符串
for (int i = 0; i < s.Length; i++)
{
//格式后的字符是小写的字母
//如果使用大写X则格式后的字符是大写字符
pwd = pwd + s[i].ToString("X");
}
return pwd;
}
}
}