DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Return A SHA1 Hexa Encoded String

07.27.2005
| 8014 views |
  • submit to reddit
        
public static string SHA1_ComputeHexaHash (string text) {
	// Gets the SHA1 hash for text
	SHA1 sha1 = new SHA1CryptoServiceProvider();
	byte[] data = Encoding.Default.GetBytes(text);
	byte[] hash = sha1.ComputeHash(data);
	// Transforms as hexa
	string hexaHash = "";
	foreach (byte b in hash) {
		hexaHash += String.Format("{0:x2}", b);
	}
	// Returns SHA1 hexa hash
	return hexaHash;
}