时间:2022-12-03 12:10:07 | 栏目:.NET代码 | 点击:次
public static string GenerateMD5Hash(string str) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] byteArray = Encoding.UTF8.GetBytes(str); byteArray = md5.ComputeHash(byteArray); string hashedValue = ""; foreach (byte b in byteArray) { hashedValue += b.ToString("x2"); } return hashedValue; }
public static string GenerateMD5Hash(string str) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] byteArray = Encoding.UTF8.GetBytes(str); byteArray = md5.ComputeHash(byteArray); StringBuilder mdStrBuff = new StringBuilder(); for (int i = 0; i < byteArray.Length; i++) { if ((0xFF & byteArray[i]).ToString("x").Length == 1) { mdStrBuff.Append("0"); } mdStrBuff.Append((0xFF & byteArray[i]).ToString("x")); } string r = mdStrBuff.ToString(); return r; }
def hash_md5(s): res = s h = hashlib.md5() h.update(res.encode(encoding='utf-8')) return h.hexdigest()