SHA-1 Hash Generator
Get the SHA-1 hash of any text or file as you type, check it against a hash you were given, or work out the ID Git gives a file. Copy it as hex or Base64. Everything runs in your browser.
SHA-1("hello world") = 2aae6c35…1ee846ed
11 characters → 11 bytes of UTF-8
Hash
SHA-140 characters
2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
Fine-tune
Line breaks in text
Everything is hashed in your browser. Your text and files are never uploaded.
How to generate a SHA-1 hash
- Type or paste text into the box, or switch to File and drop in any file.
- The 40-character SHA-1 hash appears straight away and updates as you type. Copy it as lowercase hex, uppercase hex or Base64.
- To compare with a hash from a website, a database or another program, paste it into Check against a hash.
Text is hashed as UTF-8, so the result is the same as sha1() in PHP, hashlib.sha1 in Python or sha1sum on Linux for the same text. If you need the ID Git uses for a file, open Fine-tune and turn on Hash as a Git object.
Worked example: a file's Git ID
Git names every file it stores by a SHA-1 hash, but hashing the file yourself gives a different answer. That is because Git hashes a short header first. Take a file containing hello world and a line break, 12 bytes in all:
Step 1: The plain SHA-1 of the file
Step 2: Git puts “blob”, the size and a zero byte in front
Step 3: The SHA-1 of that is the Git ID
Result: 3b18e512…, the same as git hash-object gives for the file. Turning on Hash as a Git object adds the header for you, for text or a whole file. This covers files (Git calls them blobs); commit and folder IDs are built from different data.
How long is a SHA-1 hash?
Always 40 hex characters: 160 bits, or 20 bytes, whatever the size of the input. In Base64 it is 28 characters ending in =. The length is the quickest way to tell hash types apart:
| Hash | Hex characters | hello world starts with | Still secure? |
|---|---|---|---|
| MD5 | 32 | 5eb63bbb… | No |
| SHA-1 | 40 | 2aae6c35… | No |
| SHA-256 | 64 | b94d27b9… | Yes |
| SHA-512 | 128 | 309ecc48… | Yes |
If the hash you have is 64 or 128 characters long, it is SHA-256 or SHA-512: use the SHA-2 Hash Generator instead. The tool above tells you when a pasted hash is the wrong type.
Why doesn't my SHA-1 hash match?
Almost always because the bytes are not exactly the same, even when the text looks identical. Here is the SHA-1 of hello world with small, easy-to-miss differences:
| What is different | SHA-1 starts with | What to do |
|---|---|---|
| Nothing: plain hello world | 2aae6c35… | This is the reference. |
| A line break at the end | 22596363… | Tick “Add a line break at the end”. echo and saved files add one. |
| A Windows line break (CRLF) at the end | 88a5b867… | Choose Windows (CRLF) as well. |
| A space at the end | 0b1f51a2… | Remove it; the tool warns about it. |
| A capital H | 7b502c3a… | Hashes are case-sensitive about the text. |
| Hashed by Git | 95d09f2b… | Turn on “Hash as a Git object”. |
| Hash written in capitals | 2AAE6C35… | Same hash. Hex letters are not case-sensitive. |
| Hash written in Base64 | Kq5sNclP… | Same hash, different alphabet. Switch the output to Base64. |
In code, the usual culprit is the encoding: hash the UTF-8 bytes of the string. Older .NET examples that use Encoding.Unicode hash UTF-16 and get a different result for the same text. And when comparing a Git ID, remember that Git may store a file with different line breaks than the copy on a Windows disk, which changes its ID.
Is SHA-1 still secure, and where is it still used?
No, not where someone might cheat on purpose. In 2017 researchers from Google and CWI Amsterdam published two different PDF files with the same SHA-1 hash (the “SHAttered” attack). In 2020 a stronger attack showed that a matching pair could be made for about US$45,000 of computing time. Browsers stopped trusting SHA-1 website certificates in 2017, and NIST has told organisations to stop using it altogether by 31 December 2030.
That does not make a SHA-1 hash useless. It still reliably spots accidental changes, such as a corrupted download, and it is still built into systems you probably use:
- Git names commits and files by SHA-1. It uses a hardened version that detects the known attack, and newer repositories can switch to SHA-256.
- Authenticator apps (the six-digit codes for two-factor login) mostly use HMAC-SHA1. HMAC mixes in a secret key and is not affected by the collision attacks.
- Have I Been Pwned checks passwords against known leaks by sending only the first five characters of their SHA-1 hash.
- Older downloads and databases that published SHA-1 checksums or stored SHA-1 values, which is why you may need to reproduce one.
SHA-1 vs SHA-256: which should you use?
Use SHA-1 only to match something that already uses it: a published SHA-1 checksum, a Git ID, a legacy database column or an API that asks for it. The two hashes are not interchangeable, so a SHA-256 can never be checked against a SHA-1.
Use SHA-256 for anything new: checksums you publish, file fingerprints, signatures. It is 64 characters instead of 40 and has no known weaknesses; it is a little slower, which you will rarely notice. If you are moving a system off SHA-1, the SHA-2 Hash Generator makes SHA-256, SHA-384 and SHA-512 the same way. Neither is suitable for storing passwords; that needs a slow password hash such as Argon2id or bcrypt.
Frequently asked questions
Can a SHA-1 hash be decrypted?
No. A hash is not encrypted text, and there is no key or reverse step. Sites that "decrypt" SHA-1 look the hash up in lists of common words and leaked passwords, which only works for short, guessable inputs.
What is the SHA-1 hash of an empty string?
da39a3ee5e6b4b0d3255bfef95601890afd80709. If you see it where you expected something else, the input was empty. In Git, an empty file has the ID e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 because of the header Git adds.
Is HMAC-SHA1 still safe?
Yes, for now. The attacks on SHA-1 find two inputs with the same hash, which does not help forge an HMAC without the secret key. It is still the default for authenticator codes, but new designs should use HMAC-SHA256.
Are my text and files uploaded?
No. The hash is worked out by your browser on your device, and nothing you type or drop in leaves your computer. Large files are read in pieces, so multi-gigabyte files work too.
Sources
- NIST FIPS 180-4, Secure Hash Standard: the definition of SHA-1 and its 160-bit output
- NIST Retires SHA-1 Cryptographic Algorithm: the plan to phase SHA-1 out by 31 December 2030
- SHAttered: the first practical SHA-1 collision, two PDFs with the same hash (2017)
- Git: hash function transition: Git's use of SHA-1, its collision detection and the move to SHA-256
- Pro Git: Git Objects: how Git builds the "blob <size>" header before hashing a file
- RFC 6238, TOTP: the one-time password standard behind authenticator apps, which defaults to HMAC-SHA1
Related Tools
PBKDF2 and key derivation functions.
SHA-256, SHA-384 and SHA-512 hashes of text or files.
Generate salts for encryption and hashing.
Break secrets into verifiable shares.