using System; using System.Text; using System.Security.Cryptography; public static class Md5SignatureDemo { private static readonly char[] HexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; // Use the MD5 algorithm to regenerate a signature string with a unique value based on the string in the specified UTF-8 encoding format // encryptContent: The signature string is generated using the MD5 algorithm based on the string in this UTF-8 encoding format public static string PMakeMd5Signature(this string encryptContent) { if (string.IsNullOrEmpty(encryptContent)) { return string.Empty; } byte[] bInputs = Encoding.UTF8.GetBytes(encryptContent); // Get the 'MessageDigest' object of the MD5 digest algorithm var oMd5 = MD5.Create(); // Updates the summary with the specified bytes oMd5.ComputeHash(bInputs); // Get ciphertext byte[] bHashes = oMd5.Hash; // Convert the ciphertext into hexadecimal string form int iLen = bHashes.Length; char[] cBuffers = new char[iLen * 2]; int j = 0; for (int i = 0; i < iLen; i++) { byte bZero = bHashes[i]; cBuffers[j++] = HexDigits[(bZero >> 4) & 0xf]; cBuffers[j++] = HexDigits[bZero & 0xf]; } string sRet = new string(cBuffers); return sRet; } }