Walkthrough: Checking Whether a Hash Value Matches Some Text
Retired Content |
---|
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
The latest Enterprise Library information can be found at the Enterprise Library site. |
This walkthrough demonstrates how to use the Cryptography Application Block to check whether a previously generated hash matches the hash for some text.
To reproduce the demonstration
Declare the appropriate variables and constants.
const string hashProvider = "hashprovider"; byte[] generatedHash;
'Usage Const hashProvider As String = "hashprovider" Dim generatedHash As Byte()
Obtain the text from the user.
byte[] valueToHash = Encoding.UTF8.GetBytes("password");
'Usage Dim valueToHash As Byte() = Encoding.UTF8.GetBytes("password")
Call the static CompareHash method of the Cryptographer class to obtain the hash, supplying the name of the configured hash provider to be used. This code assumes that the member variable generatedHash contains a previously generated hash for some text.
bool comparisonSucceeded = Cryptographer.CompareHash(hashProvider, valueToHash, generatedHash);
'Usage Dim comparisonSucceeded As Boolean = Cryptographer.CompareHash(hashProvider, valueToHash, generatedHash)