SHA-1 Hash Last Updated : 18 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report SHA-1 or Secure Hash Algorithm 1 is a cryptographic algorithm that 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 been considered insecure since 2005. Major tech giants browsers like Microsoft, Google, Apple, and Mozilla have stopped accepting SHA-1 SSL certificates by 2017. SHA-1 HashHow SHA-1 WorksThe block diagram of the SHA-1 (Secure Hash Algorithm 1) algorithm. Here’s a detailed description of each component and process in the diagram:Components and Process Flow:Message (M):The original input message that needs to be hashed.Message Padding:The initial step where the message is padded to ensure its length is congruent to 448 modulo 512. This step prepares the message for processing in 512-bit blocks.Round Word Computation (WtW_tWt):After padding, the message is divided into blocks of 512 bits, and each block is further divided into 16 words of 32 bits. These words are then expanded into 80 32-bit words, which are used in the subsequent rounds.Round Initialize (A, B, C, D, and E):Initialization of five working variables (A, B, C, D, and E) with specific constant values. These variables are used to compute the hash value iteratively.Round Constants (KtK_tKt):SHA-1 uses four constant values (K1K_1K1, K2K_2K2, K3K_3K3, K4K_4K4), each applied in a specific range of rounds:K1K_1K1 for rounds 0-19K2K_2K2 for rounds 20-39K3K_3K3 for rounds 40-59K4K_4K4 for rounds 60-79Rounds (0-79):The main computation loop of SHA-1, divided into four stages (each corresponding to one of the constants K1K_1K1 to K4K_4K4). In each round, a combination of logical functions and operations is performed on the working variables (A, B, C, D, and E) using the words generated in the previous step.Final Round Addition:After all 80 rounds, the resulting values of A, B, C, D, and E are added to the original hash values to produce the final hash.MPX (Multiplexing):Combines the results from the final round addition to form the final message digest.Summary of Steps:Input (Message M): The process starts with the input message MMM.Message Padding: The message is padded to meet the length requirements.Word Computation: The padded message is divided into blocks and further into words, which are expanded for use in the rounds.Initialization: Initial hash values are set.Round Processing: The main loop performs 80 rounds of computation using the message words and round constants.Final Addition: The results from the rounds are added to the initial hash values.Output (Hash Value): The final message digest is produced.Cryptographic Hash Functions in JavaTo calculate cryptographic hash values in Java, the MessageDigest class is used, which is part of the java.security package. The MessageDigest class provides the following cryptographic hash functions:MD2MD5SHA-1SHA-224SHA-256SHA-384SHA-512These 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. Examples:Input : hello worldOutput : 2aae6c35c94fcfb415dbe95f408b9ce91ee846edInput : GeeksForGeeks Output : addf120b430021c36c232c99ef8d926aea2acd6bExample 1: Below program shows the implementation of SHA-1 hash in Java. Java // Java program to calculate SHA-1 hash value import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class GFG { public static String encryptThisString(String input) { try { // getInstance() method is called with algorithm SHA-1 MessageDigest md = MessageDigest.getInstance("SHA-1"); // digest() method is called // to calculate message digest of the input string // returned as array of byte byte[] messageDigest = md.digest(input.getBytes()); // Convert byte array into signum representation BigInteger no = new BigInteger(1, messageDigest); // Convert message digest into hex value String hashtext = no.toString(16); // Add preceding 0s to make it 40 digits long while (hashtext.length() < 40) { hashtext = "0" + hashtext; } // return the HashText return hashtext; } // For specifying wrong message digest algorithms catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } } // Driver code public static void main(String args[]) throws NoSuchAlgorithmException { System.out.println("HashCode Generated by SHA-1 for:"); String s1 = "GeeksForGeeks"; System.out.println("\n" + s1 + " : " + encryptThisString(s1)); String s2 = "hello world"; System.out.println("\n" + s2 + " : " + encryptThisString(s2)); } } OutputHashCode Generated by SHA-1 for: GeeksForGeeks : addf120b430021c36c232c99ef8d926aea2acd6b hello world : 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed Example 2: Below program shows the implementation of SHA-1 hash in PHP. PHP <?php echo "HashCode Generated by SHA-1 for:"; echo ("<br>"); $myString = "hello world"; echo $myString." : "; echo sha1($myString); echo ("<br>"); $myString2 = "GeeksForGeeks"; echo $myString2." : "; echo sha1($myString2); ?> Output:HashCode Generated by SHA-1 for:hello world : 2aae6c35c94fcfb415dbe95f408b9ce91ee846edGeeksForGeeks : addf120b430021c36c232c99ef8d926aea2acd6bExample 3: Below program shows the implementation of SHA-1 hash in JavaScript. HTML <!DOCTYPE html> <html> <head> <title>sha1 Hash function</title> <script src= "https://cdnjs.cloudflare.com/ajax/libs/js-sha1/0.6.0/sha1.min.js"> </script> </head> <body> <h1>GeeksforGeeks</h1> <h2>JavaScript sha1 Hash function</h2> <p id="pId"></p> <p id="pId2"></p> <!-- Script to return math property values --> <script> var myString = "hello world"; var text = sha1(myString); document.getElementById("pId").innerHTML = myString + " : " + text; var myString2 = "GeeksForGeeks"; var text2 = sha1(myString2); document.getElementById("pId2").innerHTML = myString2 + " : " + text2; </script> </body> </html> Output:GeeksforGeeksJavaScript sha1 Hash functionhello world : 2aae6c35c94fcfb415dbe95f408b9ce91ee846edGeeksForGeeks : addf120b430021c36c232c99ef8d926aea2acd6bApplications:Cryptography: The main application of SHA1 is to protect communications from being intercepted by outside parties. From a given data input, SHA1 generates a fixed-size, singular, and irreversible hash value. The integrity of the data can then be confirmed by comparing this hash value to the original hash value. This makes it possible to confirm that the data was not changed or tampered with in any manner during transmission.Data Integrity: In many industries, such as finance, healthcare, and government, data integrity is a major concern. Data integrity in a system is checked using the SHA1 algorithm. A fingerprint of the original data is created using a hash value produced by the SHA1 algorithm. If the data changes in any way, the hash value will also change, indicating that the data has been tampered with. Digital Signatures: Digital signatures are used to confirm the legitimacy of digital documents and messages. The digital document or communication is hashed using the SHA1 technique, and its hash value is subsequently encrypted with the sender's private key. Using the sender's public key to decode the message, the recipient can then compare the hash value to the original value.Digital Forensics: In digital forensics, a hash of a file containing digital evidence can be produced using the SHA1 algorithm. To ensure that the evidence hasn't been altered with during the investigation, utilize this hash value as proof. It gives proof that the file has not been altered if the hash values of the original file and the evidence file match. Password Storage: SHA1 can be used to save passwords. A hash of the password is generated using SHA1 when a user creates a password. The password itself is then substituted in a database for the hash value. The user's password is hashed with SHA1 when they attempt to log in, and the resulting hash is compared to a previously generated hash.Software Updates: The integrity of software updates can be guaranteed using SHA1. The SHA1 hash of the update file can be made public on the software vendor's website when an update is made available. By comparing the hash of the downloaded file with the published hash, users can download the update and ensure its integrity. Comment More infoAdvertise with us Next Article RC4 Encryption Algorithm R RishabhPrabhu Follow Improve Article Tags : Java Hash Practice Tags : HashJava Similar Reads Cryptography Tutorial Cryptography is a technique of securing communication by converting plain text into unintelligible ciphertext. It involves various algorithms and protocols to ensure data confidentiality, integrity, authentication, and non-repudiation. The two primary types of cryptography are symmetric key cryptogr 7 min read Cryptography BasicCryptography IntroductionCryptography is the study and practice of techniques for secure communication in the presence of third parties called adversaries. It deals with developing and analyzing protocols that prevents malicious third parties from retrieving information being shared between two entities thereby following th 4 min read History of CryptographyHumans have two basic needs when we take about communication. One is the need to communicate selectively, to communicate and share information. These two basic needs while communicating gave rise to coding and encrypting the messages in such a way that only intended people could have access to the i 4 min read Cryptography and its TypesCryptography is a technique of securing information and communications using codes to ensure confidentiality, integrity and authentication. Thus, preventing unauthorized access to information. The prefix "crypt" means "hidden" and the suffix "graphy" means "writing". In Cryptography, the techniques 8 min read Cryptography and Network Security PrinciplesIn the present-day scenario security of the system is the sole priority of any organization. The main aim of any organization is to protect their data from attackers. In cryptography, attacks are of two types: Passive attacks and Active attacks. Passive attacks are those that retrieve information fr 9 min read Cryptography AlgorithmPublic Key EncryptionPublic key cryptography provides a secure way to exchange information and authenticate users by using pairs of keys. The public key is used for encryption and signature verification, while the private key is used for decryption and signing. When the two parties communicate with each other to transfe 7 min read Traditional Symmetric CiphersThe two types of traditional symmetric ciphers are Substitution Cipher and Transposition Cipher. The following flowchart categories the traditional ciphers: 1. Substitution Cipher: Substitution Ciphers are further divided into Mono-alphabetic Cipher and Poly-alphabetic Cipher. First, let's study abo 3 min read What is an Asymmetric Encryption?Asymmetric encryption, also known as public-key cryptography, is a type of encryption that uses a pair of keys to encrypt and decrypt data. The pair of keys includes a public key, which can be shared with anyone, and a private key, which is kept secret by the owner. What is an Asymmetric Encryption? 8 min read Difference between Private key and Public keyCryptography as a field emphasizes the need to guarantee secure communication and data privacy. There are mainly two approaches available to perform this operation: â Private Key Cryptography (RIC or Symmetric Key Cryptography) and Public Key Cryptography (PKE or Asymmetric Key Cryptography). Althou 6 min read What is data encryption?What is Data Encryption?Data encryption is the process of converting readable information (plaintext) into an unreadable format (ciphertext) to protect it from unauthorized access. It is a method of preserving data confidentiality by transforming it into ciphertext, which can only be decoded using a unique decryption key p 10 min read Encryption, Its Algorithms And Its FutureEncryption plays a vital role in todayâs digital world, serving a major role in modern cyber security. It involves converting plain text into cipher text, ensuring that sensitive information remains secure from unauthorized access. By making data unreadable to unauthorized parties, encryption helps 10 min read SHA-1 HashSHA-1 or Secure Hash Algorithm 1 is a cryptographic algorithm that 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 7 min read RC4 Encryption AlgorithmRC4 is a stream cipher and variable-length key algorithm. This algorithm encrypts one byte at a time (or larger units at a time). A key input is a pseudorandom bit generator that produces a stream 8-bit number that is unpredictable without knowledge of the input key, The output of the generator is c 6 min read Hash Functions in System SecurityHash Function is a function that has a huge role in making a System Secure as it converts normal data given to it as an irregular value of fixed length. We can imagine it to be a Shaker in our homes. When we put data into this function it outputs an irregular value. The Irregular value it outputs is 4 min read Blowfish Algorithm with ExamplesBlowfish is an encryption technique designed by Bruce Schneier in 1993 as an alternative to the DES Encryption Technique. It is significantly faster than DES and provides a good encryption rate with no effective cryptanalysis technique found to date. It is one of the first secure block ciphers not s 14 min read Difference between MD5 and SHA1MD5 stands for Message Digest and SHA1 stands for Secure Hash Algorithm both are cryptographic hash algorithms used for security purposes. SHA-1 or Secure Hash Algorithm 1 is a cryptographic algorithm that takes an input and produces a 160-bit (20-byte) hash value. This hash value is known as a mess 5 min read Difference between RSA algorithm and DSAIn cryptography, the two commonly used algorithms in modern cryptography for secure data transmission and to ensure the signatures of digital signatures, are the Rivest-Shamir-Adleman (RSA) algorithm and Digital Signature Algorithm (DSA). We'll learn about RSA and DSA, how they work when are they us 8 min read Classical Encryption TechniquesSymmetric Cipher ModelSymmetric Encryption is the most basic and old method of encryption. It uses only one key for the process of both the encryption and decryption of data. Thus, it is also known as Single-Key Encryption. A few basic terms in Cryptography are as follows: Plain Text: original message to be communicated 3 min read Substitution CipherHiding some data is known as encryption. When plain text is encrypted it becomes unreadable and is known as ciphertext. In a Substitution cipher, any character of plain text from the given fixed set of characters is substituted by some other character from the same set depending on a key. For exampl 6 min read Columnar Transposition CipherGiven a plain-text message and a numeric key, cipher/de-cipher the given text using Columnar Transposition Cipher The Columnar Transposition Cipher is a form of transposition cipher just like Rail Fence Cipher. Columnar Transposition involves writing the plaintext out in rows, and then reading the c 12 min read Block Cipher , DES and AESBlock Cipher Design PrinciplesBlock ciphers are built in the Feistel cipher structure. Block cipher has a specific number of rounds and keys for generating ciphertext.Block cipher is a type of encryption algorithm that processes fixed-size blocks of data, usually 64 or 128 bits, to produce ciphertext. The design of a block ciphe 3 min read Block Cipher modes of OperationEncryption algorithms are divided into two categories based on the input type: block cipher and stream cipher. A block cipher is an encryption algorithm that takes a fixed-size input (e.g., b bits) and produces a ciphertext of b bits. If the input is larger than b bits, it can be divided further. Th 8 min read Data Encryption Standard (DES) | Set 1Data Encryption Standard (DES) is a symmetric block cipher. By 'symmetric', we mean that the size of input text and output text (ciphertext) is same (64-bits). The 'block' here means that it takes group of bits together as input instead of encrypting the text bit by bit. Data encryption standard (DE 15+ min read Double DES and Triple DESAs we know the Data encryption standard (DES) uses 56 bit key to encrypt any plain text which can be easily be cracked by using modern technologies. To prevent this from happening double DES and triple DES were introduced which are much more secured than the original DES because it uses 112 and 168 2 min read Strength of Data encryption standard (DES)Data Encryption Standard (DES) is a symmetric block cipher. By âsymmetricâ, we mean that the size of input text and output text (ciphertext) is same (64-bits). The block here means that it takes group of bits together as input instead of encrypting the text bit by bit. Data encryption standard (DES) 5 min read AES Full FormAES stands for Advanced Encryption Standard and is a majorly used symmetric encryption algorithm. It is mainly used for encryption and protection of electronic data. It was used as the replacement of DES(Data encryption standard) as it is much faster and better than DES. AES consists of three block 2 min read Advanced Encryption Standard (AES)Advanced Encryption Standard (AES) is a highly trusted encryption algorithm used to secure data by converting it into an unreadable format without the proper key. It is developed by the National Institute of Standards and Technology (NIST) in 2001. It is is widely used today as it is much stronger t 7 min read Difference Between AES and DES CiphersDES (Data Encryption Standard) and AES (Advanced Encryption Standard) are both symmetric key encryption algorithms used to secure data. They use the same key for both encryption and decryption, but differ significantly in strength and design. Advanced Encryption Standard (AES) is a highly trusted en 5 min read Public Key Cryptography and RSARSA Algorithm in CryptographyRSA(Rivest-Shamir-Adleman) Algorithm is an asymmetric or public-key cryptography algorithm which means it works on two different keys: Public Key and Private Key. The Public Key is used for encryption and is known to everyone, while the Private Key is used for decryption and must be kept secret by t 13 min read Implementation of Diffie-Hellman AlgorithmDiffie-Hellman algorithm:The Diffie-Hellman algorithm is being used to establish a shared secret that can be used for secret communications while exchanging data over a public network using the elliptic curve to generate points and get the secret key using the parameters. For the sake of simplicity 10 min read ElGamal Encryption AlgorithmElGamal Encryption is a public-key cryptosystem. It uses asymmetric key encryption to communicate between two parties and encrypt the message. This cryptosystem is based on the difficulty of finding discrete logarithms in a cyclic group that is even if we know ga and gk, it is extremely difficult to 6 min read What is Cryptanalysis?Understanding Rainbow Table AttackWhat is a Rainbow Table? The passwords in a computer system are not stored directly as plain texts but are hashed using encryption. A hash function is a 1-way function, which means that it can't be decrypted. Whenever a user enters a password, it is converted into a hash value and is compared with t 4 min read What is a Dictionary Attack?A Dictionary Attack is an attack vector used by the attacker to break in a system, which is password protected, by putting technically every word in a dictionary as a form of password for that system. This attack vector is a form of Brute Force Attack. The dictionary can contain words from an Englis 2 min read Brute Force AttackA Brute force attack is a well known breaking technique, by certain records, brute force attacks represented five percent of affirmed security ruptures. A brute force attack includes 'speculating' username and passwords to increase unapproved access to a framework. Brute force is a straightforward a 3 min read Comman CryptographyCustom Building Cryptography Algorithms (Hybrid Cryptography)Cryptography can be defined as an art of encoding and decoding the patterns (in the form of messages). Cryptography is a very straightforward concept which deals with manipulating the strings (or text) to make them unreadable for the intermediate person. It has a very effective way to encrypt or dec 15+ min read An Overview of Cloud CryptographyCloud cryptography is a set of techniques used to secure data stored and processed in cloud computing environments. It provides data privacy, data integrity, and data confidentiality by using encryption and secure key management systems. Common methods used in cloud cryptography include:Symmetric en 4 min read Quantum CryptographyThe uncertainty principle of quantum physics builds the earliest foundations for quantum cryptography. With quantum computers of the future being expected to solve discrete logarithmic problems and the popularly known cryptography methods such as AES, RSA, DES, quantum cryptography becomes the fores 7 min read Image Steganography in CryptographyThe word Steganography is derived from two Greek words- 'stegos' meaning 'to cover' and 'grayfia', meaning 'writing', thus translating to 'covered writing', or 'hidden writing'. Steganography is a method of hiding secret data, by embedding it into an audio, video, image, or text file. It is one of t 8 min read DNA CryptographyCryptography is the branch of science that deals with the encoding of information to hide messages. It plays a vital role in the infrastructure of communication security. The Pioneering work had been done by Ashish Gehani et al and Amin et al after Leonard Max Adleman had shown the capability of mol 12 min read Caesar Cipher in CryptographyThe Caesar Cipher is one of the simplest and oldest methods of encrypting messages, named after Julius Caesar, who reportedly used it to protect his military communications. This technique involves shifting the letters of the alphabet by a fixed number of places. For example, with a shift of three, 11 min read One Time Password (OTP) algorithm in CryptographyAuthentication, the process of identifying and validating an individual is the rudimentary step before granting access to any protected service (such as a personal account). Authentication has been built into the cyber security standards and offers to prevent unauthorized access to safeguarded resou 7 min read Data Integrity in CryptographyMessage Authentication CodesMessage Authentication Codes are the codes which plays their role in two important functions: Authentication Detection and Falsification Detection. Where do we need these codes? Suppose User A send message to user B with message - 'abc'. A encrypts the message using Shared - Key Cryptosystem for enc 2 min read Digital Signatures and CertificatesDigital signatures and certificates are two key technologies that play an important role in ensuring the security and authenticity of online activities. They are essential for activities such as online banking, secure email communication, software distribution, and electronic document signing. By pr 11 min read Public Key InfrastructurePublic key infrastructure or PKI is the governing body behind issuing digital certificates. It helps to protect confidential data and gives unique identities to users and systems. Thus, it ensures security in communications. The public key infrastructure uses a pair of keys: the public key and the p 7 min read Like