SHA-2 (SHA-256, SHA-512, SHA-384) Hash Code Generator Tool

Share:

This online SHA-2 hash code generator tool will generate SHA-2 (SHA-256, SHA-512, SHA-384) hash codes for any given string. Also get the source code for SHA-2 hash code generator in C#.Net, Java and PHP.

*
     


About SHA-2 (Sha2) Hash Generator Tool

This sha hash generator tool generates SHA-2 hash codes from the entered text. I've provided three commonly used SHA-2 hashing algorithms SHA-256, SHA-512 and SHA-384. SHA-256 calculator (or) converter is the widely used sha-2 hash code generator compared to the SHA-512 calculator or SHA-384 calculator.

Steps for using this tool:

  1. Enter or paste your text in the first text box and click one of the three SHA-2 hashing algorithm buttons Generate SHA-256 Hash (to generate sha256 hash code), Generate SHA-512 Hash (to generate sha512 hash code) or Generate SHA-384 Hash (to generate sha384 hash code).
  2. The SHA-2 hash code for the entered text appears in the second box.

SHA-2 Cryptographic Hash Algorithm

SHA-2 Hash Code Cryptography

SHA-2 Cryptography

SHA-2 is is the 2nd version of sha hash generator algorithm. It is otherwise called as Secure Hash Algorithm 2. SHA-2 is a set of 6 hashing algorithm (SHA-256, SHA-512, SHA-224, SHA-384, SHA-512/224, SHA-512/256). The term SHA-2 is misrepresented for SHA-256. Don't get confused when someone asks you for SHA-2 hash code. Actually they are asking for SHA-256.

  1. SHA-256

    SHA-256 is a 256 bit (32 bytes) hashing algorithm which can calculate hash code for an input up to 264-1 bits. It undergoes 64 rounds off hashing. The calculated hash code will be a 64 digit hexadecimal number. For example, the SHA-256 hash code for www.mytecbits.com is 575f62a15889fa8ca55514a10754d2f98e30c57c4538f0f3e39dc53114533857.
  2. SHA-512

    SHA-512, as the name suggests, is a 512 bit (64 bytes) hashing algorithm which can calculate hash code for an input up to 2128-1 bits. It undergoes 80 rounds off hashing. So, SHA-512 is stronger hashing than SHA-256. The calculated hash code will be a 124 digit hexadecimal number. For example, the SHA-256 hash code for www.mytecbits.com is d91359957c1a7f11931bc0cfb1082b0061d5bb5c7bd76d789f0e2ff2b3769edde9d 53993946c23677404a8acf0f4a70134bfd2f8f182103a84ef789054241516.
  3. SHA-224

    SHA-224 is the truncated version for SHA-256. The output hash code for this is 224 bit. This method can calculate hash code for an input up to 264-1 bits. It undergoes 64 rounds off hashing. This method of hash coding is not so commonly used because of it's out put bit size
  4. SHA-384

    SHA-384 is the truncated version for SHA-512. The output hash code for this is 384 bit (i.e. 96 digit hexadecimal code). This method can calculate hash code for an input up to 2128-1 bits. It undergoes 80 rounds off hashing. For example, the SHA-256 hash code for www.mytecbits.com is 5e87350befd97b8ae2512e5b7bcb17ab76ab845c11fd7b0c8bd 7d66ad635530c4da0e03f8a639283c39827aa24a69087.
  5. SHA-512/224

    SHA-512/224 is the truncated version for SHA-512. The output hash code for this is 224 bit code. This method can calculate hash code for an input up to 2128-1 bits.
  6. SHA-512/256

    Just like the previous method, SHA-512/256 is also a truncated version for SHA-512. The output hash code for this is 256 bit code. This method can calculate hash code for an input up to 2128-1 bits. This method undergoes 80 rounds of hashing.

Uses of SHA-2 Hashing Algorithm

  1. SHA-2 is used as cryptography algorithm for SSH, SSL, TLS,... protocols.
  2. Generating SHA-2 hash code for strings and texts will be useful for password encryption, validating the authenticity of email content, etc..
  3. Another common example is to verify the file downloaded from internet. While downloading a file from internet there are possibility of the file corrupted due to internet disconnections ot the file got tampered with. To verify the authenticity of the downloaded file, the SHA-2 hash code of the downloaded file can be verified with the SHA-2 hash code generated from the source file. Thus any tampering or data loss can be identified.

Programming SHA-256 Hash Generator

Major programming languages has inbuilt SHA-256 classes to generate and verify SHA-256 hash codes.

.Net

.Net has System.Security.Cryptography.SHA256 abstract class. This class has ComputeHash(Byte[]), ComputeHash(Stream) and ComputeHash(Byte[], Int32, Int32) methods which can be used to generate SHA-256 hash codes.

A simple .Net C# class method which takes a string as input and returns SHA-256 hash code.

// SHA-256 Hash Code Generator Method
public static string SHA256Generator(string strInput)
{
	SHA256 sha256 = new SHA256CryptoServiceProvider();

        //provide the string in byte format to the ComputeHash method. 
	//This method returns the SHA-256 hash code in byte array
	byte[] arrHash = sha256.ComputeHash(Encoding.UTF8.GetBytes(strInput));

        // use a Stringbuilder to append the bytes from the array to create a SHA-256 hash code string.
	StringBuilder sbHash = new StringBuilder();

        // Loop through byte array of the hashed code and format each byte as a hexadecimal code.
	for (int i = 0; i < arrHash.Length; i++)
	{
		sbHash.Append(arrHash[i].ToString("x2"));
	}

        // Return the hexadecimal SHA-256 hash code string.
	return sbHash.ToString();
}

Java

In Java you can use the MessageDigest abstract class to generate the SHA-256 hash code for a string

A simple java class method which takes a string as input and returns SHA-256 hash code.

import java.math.BigInteger;
import java.security.MessageDigest;
 
public class SHA256 {
    public static String GenerateHash(String input) {
        MessageDigest objSHA = MessageDigest.getInstance("SHA-256");
        byte[] bytSHA = objSHA.digest(input.getBytes());
        BigInteger intNumber = new BigInteger(1, bytSHA);
        String strHashCode = intNumber.toString(16);
		
        // pad with 0 if the hexa digits are less then 64.
        while (strHashCode.length() < 64) {
            strHashCode = "0" + strHashCode;
        }
        return strHashCode;
    }
}

PHP

PHP has hash() function to calculate SHA-256 hash code.

<?php
echo hash('sha256', 'www.MyTecBits.com');
?>

Programming SHA-512 Hash Generator

Major programming languages has inbuilt SHA-512 classes to generate and verify SHA-512 hash codes.

.Net

.Net has System.Security.Cryptography.SHA512 abstract class. This class has ComputeHash(Byte[]), ComputeHash(Stream) and ComputeHash(Byte[], Int32, Int32) methods which can be used to generate SHA-512 hash codes.

A simple .Net C# class method which takes a string as input and returns SHA-512 hash code.

// SHA-512 Hash Code Generator Method
public static string SHA512Generator(string strInput)
{
	SHA512 sha512 = new SHA512CryptoServiceProvider();

        //provide the string in byte format to the ComputeHash method. 
	//This method returns the SHA-512 hash code in byte array
	byte[] arrHash = sha512.ComputeHash(Encoding.UTF8.GetBytes(strInput));

        // use a Stringbuilder to append the bytes from the array to create a SHA-512 hash code string.
	StringBuilder sbHash = new StringBuilder();

        // Loop through byte array of the hashed code and format each byte as a hexadecimal code.
	for (int i = 0; i < arrHash.Length; i++)
	{
		sbHash.Append(arrHash[i].ToString("x2"));
	}

        // Return the hexadecimal SHA-512 hash code string.
	return sbHash.ToString();
}

Java

In Java you can use the MessageDigest abstract class to generate the SHA-512 hash code for a string

A simple java class method which takes a string as input and returns SHA-512 hash code.

import java.math.BigInteger;
import java.security.MessageDigest;
 
public class 512 {
    public static String GenerateHash(String input) {
        MessageDigest objSHA = MessageDigest.getInstance("SHA-512");
        byte[] bytSHA = objSHA.digest(input.getBytes());
        BigInteger intNumber = new BigInteger(1, bytSHA);
        String strHashCode = intNumber.toString(16);
		
        // pad with 0 if the hexa digits are less then 128.
        while (strHashCode.length() < 128) {
            strHashCode = "0" + strHashCode;
        }
        return strHashCode;
    }
}

PHP

PHP has hash() function to calculate SHA-512 hash code.

<?php
echo hash('sha512', 'www.MyTecBits.com');
?>

Programming SHA-384 Hash Generator

Major programming languages has inbuilt SHA-384 classes to generate and verify SHA-384 hash codes.

.Net

.Net has System.Security.Cryptography.SHA384 abstract class. This class has ComputeHash(Byte[]), ComputeHash(Stream) and ComputeHash(Byte[], Int32, Int32) methods which can be used to generate SHA-384 hash codes.

A simple .Net C# class method which takes a string as input and returns SHA-384 hash code.

// SHA-384 Hash Code Generator Method
public static string SHA384Generator(string strInput)
{
	SHA384 sha384 = new SHA384CryptoServiceProvider();

        //provide the string in byte format to the ComputeHash method. 
	//This method returns the SHA-384 hash code in byte array
	byte[] arrHash = sha384.ComputeHash(Encoding.UTF8.GetBytes(strInput));

        // use a Stringbuilder to append the bytes from the array to create a SHA-384 hash code string.
	StringBuilder sbHash = new StringBuilder();

        // Loop through byte array of the hashed code and format each byte as a hexadecimal code.
	for (int i = 0; i < arrHash.Length; i++)
	{
		sbHash.Append(arrHash[i].ToString("x2"));
	}

        // Return the hexadecimal SHA-384 hash code string.
	return sbHash.ToString();
}

Java

In Java you can use the MessageDigest abstract class to generate the SHA-384 hash code for a string

A simple java class method which takes a string as input and returns SHA-384 hash code.

import java.math.BigInteger;
import java.security.MessageDigest;
 
public class SHA384 {
    public static String GenerateHash(String input) {
        MessageDigest objSHA = MessageDigest.getInstance("SHA-384");
        byte[] bytSHA = objSHA.digest(input.getBytes());
        BigInteger intNumber = new BigInteger(1, bytSHA);
        String strHashCode = intNumber.toString(16);
		
        // pad with 0 if the hexa digits are less then 96.
        while (strHashCode.length() < 96) {
            strHashCode = "0" + strHashCode;
        }
        return strHashCode;
    }
}

PHP

PHP has hash() function to calculate SHA-384 hash code.

<?php
echo hash('sha384', 'www.MyTecBits.com');
?>

Reference

  • SHA-2 in wikipedia.org
  • SHA-2 hash code generation in .Net
  • SHA-2 hash code generation in Java
  • SHA-2 hash code generation in PHP

Page Last Modified On: Jul 23, 2021


Disclaimer: We took every effort to provide higher level of accuracy in the calculators, converters and tools we have added to www.MyTecBits.com Tools section. But, we cannot give any guarantee or can be held responsible for any errors, defects, faults or mistakes in any of the calculators, converters or tools. Please see detailed terms of use and liability disclaimer in Terms of Use Page.

Follow Us