articles » current » dot-net » hash-based-message-authentication-code

.NET: Hash-based Message Authentication Code

Safely store user passwords, written in C#.

About the System.Security.Cryptography Namespace

Use a hash to secure a site. This can be used for safely storing passwords. Generate a unique key using a GUID.

string MakeHashCode(string sMessageToCompute)
	//key: 8a7eff51-db15-44c7-a3c2-ddeb2053f051 THIS SHOULD BE UNIQUE TO EACH SITE
	System.Security.Cryptography.HMACSHA256 hmacsha256;
	hmacsha256 = new System.Security.Cryptography.HMACSHA256(
	int i;
	string returnString = "";
	for(i = 0; i < hmacsha256.Hash.Length; i++)
		returnString += hmacsha256.Hash[i].ToString("X2");
	return returnString;

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.