C# MD5加密

时间:2020-11-28 08:56:15
public static string Encrypt(string txt)
{
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bytes = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(txt)); return BitConverter.ToString(bytes).Replace("-", "");
} public static string Encrypt2(string txt)
{
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bytes = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(txt));
StringBuilder sb = new StringBuilder();
foreach(byte b in bytes)
{
sb.Append(b.ToString("X").PadLeft(,''));
}
return sb.ToString();
}