The SHA-2 family of cryptographic hash functions consists of six hash functions. These are:
- SHA-224, with 224 bit hash values
- SHA-256, with 256 bit hash values
- SHA-384, with 384 bit hash values
- SHA-512, with 512 bit hash values
- SHA-512/224, with 512 bit hash values
- SHA-512/256, with 512 bit hash values
Among these, SHA-256 and SHA-512 are the most commonly accepted and used hash functions computed with 32-bit and 64-bit words, respectively. SHA-224 and SHA-384 are truncated versions of SHA-256 and SHA-512 respectively, computed with different initial values.
To calculate cryptographic hashing value in Java, MessageDigest Class is used, under the package java.security.
MessagDigest Class provides following cryptographic hash function to find hash value of a text as follows:
These algorithms are initialized in static method called getInstance(). After selecting the algorithm the message digest value is calculated and the results are returned as a byte array. BigInteger class is used, to convert the resultant byte array into its signum representation. This representation is then converted into a hexadecimal format to get the expected MessageDigest.
Input : hello world
Input : GeeksForGeeks
Program: Below program shows the implementation of SHA-224 hash in Java.
HashCode Generated by SHA-224 for: GeeksForGeeks : c9e0629b317667db73eaa051cf05 f4c5896f5c0c7c2cec4589919d02 hello world : 2f05477fc24bb4faefd86517156daf decec45b8ad3cf2522a563582b
- Data Integrity
- MD5 hash in Java
- MD2 Hash In Java
- SHA-256 Hash in Java
- SHA-512 Hash In Java
- SHA-384 Hash In Java
- Implementing our Own Hash Table with Separate Chaining in Java
- SHA-1 Hash
- Hash Functions in System Security
- Data Structures | Hash | Question 1
- Data Structures | Hash | Question 2
- Data Structures | Hash | Question 3
- Data Structures | Hash | Question 4
- Data Structures | Hash | Question 5
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.util.function.IntPredicate interface in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.