public static string GetMd5Hash(String input)
{
if (input == null)
{
return null;
}
MD5 md5Hash = MD5.Create();
// 將輸入字符串轉換為字節數組並計算哈希數據
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
// 創建一個 Stringbuilder 來收集字節並創建字符串
StringBuilder sBuilder = new StringBuilder();
// 循環遍歷哈希數據的每一個字節並格式化為十六進制字符串
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// 返回十六進制字符串
return sBuilder.ToString();
}
對傳入數據進行MD5加密並返回加密后的字符串(需添加引用using System.Security.Cryptography;)
