Computing a hash creates a fixed-length numeric value from a byte array. A hash maps a variable-length binary string to a fixed-length binary string. A hash cannot be used for two-way conversion. When you apply a hash algorithm, each character gets hashed into a different binary string.
In the following example, we use the SHA1Managed algorithm to compute the hash. We compute the hash twice to check whether the result is the same. As mentioned earlier, this method is used to maintain data integrity.
In the following code, we are using the UnicodeEncoding class to convert the text to a byte array, and the SHA1Managed algorithm to compute the hash for the byte array. Once converted, we display each and every hashed byte on the screen. To validate the hash, we recompute the hash on the string and compare the hash values. This is one way to validate input data:
public...