blog.pagesd.info // Archives // Traductions

Encoder une chaine en MD5 et hexa

2005-07-27 #code-snippets,#c-sharp

public static string MD5_ComputeHexaHash (string text) {
// Gets the MD5 hash for text
MD5 md5 = new MD5CryptoServiceProvider();
byte[] data = Encoding.Default.GetBytes(text);
byte[] hash = md5.ComputeHash(data);
// Transforms as hexa
string hexaHash = "";
foreach (byte b in hash) {
hexaHash += String.Format("{0:x2}", b);
}
// Returns MD5 hexa hash
return hexaHash;
}