c# 自带的哈希和MD5 如何掉用

发布时间:2024-06-13 06:58 发布:上海旅游网

问题描述:

我要获得16位的cmd5

问题解答:

MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string outText = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(text)));

命名空间:using System.Security.Cryptography;

public static string Md532(string str)
{
string cl = str;
string pwd = "";
MD5 md5 = MD5.Create();
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
for (int i = 0; i < s.Length; i++)
{
pwd = pwd + s[i].ToString("x");
}
return pwd;
}

public static string Md516(string ConvertString)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);
t2 = t2.Replace("-", "");
t2 = t2.ToLower();
return t2;
}

System.Security.Cryptography.MD5CryptoServiceProvider

热点新闻