一、md5加密
using System.Security.Cryptography;
public string EncrytPasswordMD5(string password)
{
using (MD5 md5Hash = MD5.Create())
{
byte[] inputBytes = Encoding.ASCII.GetBytes(password);
byte[] hashBytes = md5Hash.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}
}
二、SHA256加密
using System.Security.Cryptography;
public string EncrytPassword(string password)
{
using (SHA256 sHA256 = SHA256.Create())
{
byte[] inputBytes = Encoding.ASCII.GetBytes(password);
byte[] hashBytes = sHA256.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}
}