In this article you will learn about the hash algorithm and types are available in .Net.
Hash Algorithm is one of cryptographic hash functions introduced by the national institute of standards and technology. There are few of secure hash algorithm are SAH1,MD5,SHA256,SHA384 and SHA512.
The hash is used as a unique value of fixed size representing a large amount of data and the hashes of two sets of data should match if the corresponding data also matches. Small changes to the data result in large.
In .Net System.Security.Cryptography name-space provides the cryptographic services for secure encoding and decoding of data. It will provide the hashing, random number generation and message authentication.
.Net Framework supports the following hash algorithms.
- SHA1 is the secure hash algorithm(SHA). SHA! uses 160 bits to encrypt the data
- MD5 is an algorithm gets a input of length and output digested.MD5 uses 128 bits to encrypt the data
- SHA256 is the SHA that uses 256 bits to encrypt the data
- SHA384 is the SHA that uses 384 bits to encrypt the data.
- SHA512 is the SHA that uses 512 bits to encrypt the data
Sha1 is the most widely used for the existing SHA hash functions and widely used for security applications and protocols
SHA1 Hashing Algorithm
System.Security.Cryptography namespace to write in top of using block and SHA1CryptoServiceProvider class is to assign with SHA1 Algorithm to be used
ComputeHash method compute the hash value for the specified bytes
Complete Listing of SHA1 Algorithm
byte result = new byte;
string FinalStr = "180066666password",sSignature;
sha = new SHA1CryptoServiceProvider();
result = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(FinalStr));
sSignature = Convert.ToBase64String(result);
Create instance of the SHA1CryptoServiceProvider and use ComputeHash to computes the hash value for the specified byte array. Again result convert into base64string method.