Introduction
SHA-1, also known as Secure Hash Algorithm 1, is a cryptographic hash function. SHA-512 is already discussed in detail, it is very important to go through before go ahead. It takes an input and turns out a 160-bit hash value recognized as a message digest – typically given as a hexadecimal number, 40 digits long. It was designed by the United States National Security Agency.SHA-1 is an important part of numerous commonly used security applications and protocols like TLS and SSL, PGP, SSH, S/MIME, and IPsec. Those security applications can also use MD5; both MD5 and SHA-1 have come from MD4. We already discussed on internet security (Content Security Policy) and MVC security like How to Prevent Direct URL Access In MVC, Prevent Cross-Site Request Forgery using AntiForgeryToken() in MVC.
SHA-1 and SHA-2 are secure hash algorithm that is used for legal proposes in certain U.S. Government application such as protection of sensitive unclassified information, apply within other cryptographic algorithms and protocols.
Working Example
The example below calculates SHA1 hash for data and stocks up it in result. This example presumes that there is a predefined constant DATA_SIZE.static string HashSh1(string input) { using (SHA1Managed sha1 = new SHA1Managed()) { var hashSh1 = sha1.ComputeHash(Encoding.UTF8.GetBytes(input)); // declare stringbuilder var sb = new StringBuilder(hashSh1.Length * 2); // computing hashSh1 foreach (byte b in hashSh1) { // "x2" sb.Append(b.ToString("X2").ToLower()); } // final output Console.WriteLine(string.Format("The SHA1 hash of {0} is: {1}",input,sb.ToString())); return sb.ToString(); } }
Post A Comment:
0 comments: