SHA-1 or Secure Hash Algorithm 1 is a cryptographic hash function which takes an input and produces a 160-bit (20-byte) hash value. This hash value is known as a message digest. This message digest is usually then rendered as a hexadecimal number which is 40 digits long. It is a U.S. Federal Information Processing Standard and was designed by the United States National Security Agency.
SHA-1 is now considered insecure since 2005. Major tech giants browsers like Microsoft, Google, Apple and Mozilla have stopped accepting SHA-1 SSL certificates by 2017.
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
Output : 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
Input : GeeksForGeeks
Output : addf120b430021c36c232c99ef8d926aea2acd6b
Below program shows the implementation of SHA-1 hash in Java.
HashCode Generated by SHA-1 for: GeeksForGeeks : addf120b430021c36c232c99ef8d926aea2acd6b hello world : 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
- Data Integrity
- Difference between MD5 and SHA1
- MD5 hash in Java
- SHA-512 Hash In Java
- MD2 Hash In Java
- SHA-224 Hash In Java
- SHA-384 Hash In Java
- SHA-256 Hash in Java
- Hash Functions in System Security
- Data Structures | Hash | Question 5
- Data Structures | Hash | Question 4
- Data Structures | Hash | Question 1
- Data Structures | Hash | Question 2
- Data Structures | Hash | Question 3
- Implementing our Own Hash Table with Separate Chaining in Java
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.