Over a million developers have joined DZone.

Return A SHA1 Hexa Encoded String

DZone's Guide to

Return A SHA1 Hexa Encoded String

Free Resource

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;

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}