Wednesday, July 7, 2010

Hash Algorithm

Introduction

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.

.Net
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 an 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

Example
Using System.Secuity.Cryptography;
SHA1 sha;

sha=new SHA1CryptoServiceProvider

ComputeHash method compute the hash value for the specified bytes
ComputeHash(System.Text.Encoding.UTF8.GetBytes("GivenString")

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 Compute Hash to computes the hash value for the specified byte array. Again result converts into base64string method.

Output: K6DLPjiaIvN5JLQFQHaYLcUBAug=

No comments:

Post a Comment