Security foundations Hashing vs encryption 2 min read

Hashing vs encryption

You’ve stored a database backup. On restore day, you need both to read it and to check it still matches the original. Why are those two different jobs?

  1. Encryption lets you recover the backup

    Encrypt the backup before storing it so someone who gets the stored copy can’t read its contents without the key. When it’s time to restore, use the decryption key to recover the original bytes.

    The backup can be encrypted and later recovered with a key. A separate hash of the original backup can be compared after recovery. Backup fileEncryptRecover with keyHashCompare digest

    In short Encryption protects contents and gives the key holder a way to recover them.

  2. A hash lets you compare the backup

    When creating the backup, save a SHA-256 digest in a trusted place. After decrypting the stored copy, hash the recovered file and compare the two digests. A mismatch tells you that the bytes differ. The digest itself can’t give you the backup back.

    In short Compare the hash of the same bytes at both ends.

Keep the reference digest somewhere you trust

If someone can replace both the backup and its reference digest, they can make the changed file pass the comparison. Use a reference the same person can’t also change.

Keep this

Encrypt to recover. Hash to compare.

Compare against a trusted digest of the original bytes and keep the decryption key available for restore.

Sources

Last reviewed 17 November 2026.

Next byte · Identity and access What is a salt?