Labels

slider

Recent

Navigation

SHA-512 Hash using C#

SHA512 Computes the hash for the input data, sha512 c#, how to use sha512 in c#, sha512 c# tutorial, sha512 c# salt

Introduction

SHA-2, also known as Secure Hash Algorithm 2, is a set of cryptographic hash functions. SHA-512 now discussing after SHA-1 Hash. It is widely used in security applications and protocols like TLS and SSL, PGP, SSH, S/MIME, and IPsec. It is used for verifying transactions and determining proof of stake or proof of work in several cryptocurrencies like Bitcoin. SHA-2 is a secure hash algorithm that is used for legal proposes in certain U.S. Government application such as protection of sensitive unclassified information. In our earlier discussion, also discussed about very important terms of security and performance like 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-512 Hash using C#

You can use SHA-512 hash as a unique vale of fixed size. It represents a large amount of data. In order to match hashes of two sets of data should match, only when the corresponding data also matches. Your small changes to the data will cause impulsive changes in the hash. The hash size for the SHA512 algorithm is 512 bits. This is an abstract class and the only implementation of this class is SHA512 Managed.

Working Sample

In this example, SHA512 hash is computed for data and stores in its 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();
 }
}

Suggested Reading

Share

Anjan kant

Outstanding journey in Microsoft Technologies (ASP.Net, C#, SQL Programming, WPF, Silverlight, WCF etc.), client side technologies AngularJS, KnockoutJS, Javascript, Ajax Calls, Json and Hybrid apps etc. I love to devote free time in writing, blogging, social networking and adventurous life

Post A Comment:

0 comments: