MD5的加密方法很多,今天說下MD5的十六進制加密···先貼方法····
class Program
{
static void Main(string[] args)
{
//202cb962ac59075b964b07152d234b70
string s = GetMD5("123");
Console.WriteLine(s);
Console.ReadKey();
}
/// <summary>
/// MD5十六進制加密
/// </summary>
/// <param name="str">要加密的字符串</param>
/// <returns>加密之後返回的字符串</returns>
public static string GetMD5(string str)
{
//創建MD5對象
MD5 md5 = MD5.Create();
//開始加密
//需要將字符處轉換成字節數組
byte[] buffer = Encoding.Default.GetBytes(str);
//返回一個加密好的字節數組
byte[] MD5Buffer = md5.ComputeHash(buffer);
//將字節數組轉換成字符串
string strNew = "";
for (int i = 0; i < MD5Buffer.Length; i++)
{
strNew += MD5Buffer[i].ToString("x2");
}
return strNew;
}
}
根據方法 GetMD5就可以得到想要的MD5十六進制加密