The SHA1 algorithm can be used to calculate check sum, that very useful when you want to ensure the string is not broken .Also for simple password verification.The example below show how to calculate SHA1 for given string .




///


/// Calculates SHA1 hash
///

/// input string
/// Character encoding
/// SHA1 hash

public static string CalculateSHA1(string text, Encoding enc)
{
byte[] buffer = enc.GetBytes(text);
SHA1CryptoServiceProvider cryptoTransformSHA1 =
new SHA1CryptoServiceProvider();
string hash = BitConverter.ToString(
cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
return hash;



}


The result SHA1 hash for the string "first string":

No comments: