Labels

slider

Recent

Navigation

SHA 256: Compute a SHA 256 hash using C# for effective security

SHA 256, SHA 384, SHA 512, MD5, TLS 1.3, Encryption, SHA 1, Security

Introduction

Sha-256 (Secure Hash Algorithm) is a succeeding function of algorithm Sha-2 (like SHA 384, and SHA 512, and more freshly 224 bits versions), which is the developed version of Sha-1, itself a progression of Sha-0. For the intention of fulfilling the security drawbacks of Sha-1 algorithm, NSA developed the advanced version Sha-2.

Compute a SHA 256 hash using C# for effective security

Best replacement for Old MD5 hash function

The SHA-256 algorithm gets input a maximum 2^64 length message, and outputs as a 256 bits hash. It seems that sha256 is being used more and more to replace the old md5 hash function. I think that sha256 is justly the best substitute because of its superior balance between online storage size and security. Sha-256 is a unilateral cryptographic function so you can't get the plaintext with merely the hash.
You need to make a comparison of this hash to an online database, and you’ll find it actually unique. Sha-256 is an excellent approach to store the passwords of your users, as it is a more secure way than Md5 or Sha-1 for example. Even if it is enough secure though, you should still believe using salt to tighten security. Salt is a programmatic string that you link to the user's password to compose it longer, and add unique characters. This will develop great difficulties, and most probably the password won't be stored in an online database as usual.

SHA-256 algorithm generates a unique and fixed-size 256-bit or 32-byte hash. As we know hash is a one-track function – it cannot be decrypted back. This makes it appropriate for password legalization, challenge hash verification, digital signatures, and anti-tamper.

SHA-256 for Bitcoin Security

SHA-256 is broadly used in various parts of the Bitcoin network with improved encryption and decryption based security and privacy. Data Mining uses SHA-256 as the solid proof-of-function algorithm.
Let’s have sample program of SHA 256

Step #1: Let’s take input string as plain text as follows:

// input, plain text here
string plainText = "Technology crowds";

Step #2: Compute Hash 256 


static string ComputeStringToSha256Hash(string plainText)
{
 // Create a SHA256 hash from string   
 using (SHA256 sha256Hash = SHA256.Create())
 {
  // Computing Hash - returns here byte array
  byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(plainText));

  // now convert byte array to a string   
  StringBuilder stringbuilder = new StringBuilder();
  for (int i = 0; i < bytes.Length; i++)
  {
   stringbuilder.Append(bytes[i].ToString("x2"));
  }
  return stringbuilder.ToString();
 }
}

Step 3#: Now showing final output

// Ouput of plaintext to Sha256Hash 
Console.WriteLine(string.Format("The SHA256 hash of {0} is: {1}",plainText,hashedData));

Step #4: Showing here final output of Input (Technology Crowds):

The SHA384 hash of Technology crowds is: 1E164130936A24159795AB319A52B695BB28933DF99817D50802C394D3B087A114B5EFF4603B39473703A0DD9F7FFF6F

Conclusion

Overall, SHA 256 is better Hash security algorithm than SHA-1, sha-2 AND md5. Unlike SHA-384, it’s not in use for latest security algorithm. But, TLS 1.3 is the latest security certificate with advanced SHA-512 or more algorithms.
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: