Hash Algorithm in .Net

Posted by in Windows Forms category on for Beginner level | Views : 14130 red flag

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


Using System.Secuity.Cryptography;
SHA1 sha;

sha=new SHA1CryptoServiceProvider

ComputeHash method compute the hash value for the specified bytes


Complete Listing of SHA1 Algorithm            

byte[] result = new byte[100];
SHA1 sha;
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.

Output: K6DLPjiaIvN5JLQFQHaYLcUBAug=

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Muhil an
Member Level:
Member Status: Member
Member Since: 11/30/2009 2:46:25 AM
Country: India

working as an IT System Analyst,tmuhilan at gmail com

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)