Are you using MD5 correctly in .net core?
Are you using MD5 correctly in .net core? The project environment of this article is .net 6.0 (.net 5.0 and above are supported) I believe it is very easy to obtain the MD5 of a string in .net, but a casual search on the Internet reveals that there are many versions circulating, such as: StringBuilder version (should be considered the official version, used by the most people, I found that this is also used in ABP) BitConverter version StringConcat version (string concatenation, few people use it, probably everyone knows that the performance is not good) But are they the best implementation? Let’s test it StringBuilder version public static string Md5_StringBuilder(string input) { using var md5 = MD5.Create(); var inputBytes = Encoding.UTF8.GetBytes(input); var hashBytes = md5.ComputeHash(inputBytes); var sb = new StringBuilder(); foreach (var hashByte in hashBytes) { sb.Append(hashByte.ToString(“X2”)); } return sb.ToString(); } BitConverter version public static string Md5_BitConverter(string input) { using var md5 = MD5.Create(); var inputBytes = Encoding.UTF8.GetBytes(input); var hashBytes = md5.ComputeHash(inputBytes); return BitConverter.ToString(hashBytes).Replace(“-“, “”); } StringConcat version public static string Md5_StringConcat(string input) { using var md5 = MD5.Create(); var inputBytes = Encoding.UTF8.GetBytes(input); var hashBytes = md5.ComputeHash(inputBytes); var output = string.Empty; foreach (var hashByte in hashBytes) { output += hashByte.ToString(“X2”);…