How to Decrypt Folders with `age` — Part 2/2: Recovery and Cryptography.

Learn how to decrypt and restore folders encrypted with age, and explore the cryptographic mechanisms behind its security, including scrypt and ChaCha20-Poly1305.

How to Decrypt Folders with `age` — Part 2/2: Recovery and Cryptography.
Image credit: Unknown. Please contact us if you are the owner.c


In Part 1: Encrypting Folders with age — Linux and macOS, we covered installing age, encrypting entire directories with tar, verifying encrypted archives, and safely removing unencrypted copies.

Now, let's explore how to decrypt and restore those archives and understand the cryptographic mechanisms that protect your data.

How age Protects Your Data

In age, scrypt and ChaCha20-Poly1305 perform two different cryptographic jobs. One protects the passphrase-derived encryption key; the other encrypts and authenticates your actual data.

Understanding the distinction helps explain why age is designed this way.

1. scrypt — Passphrase-based key derivation

Key derivation

A human passphrase is not suitable for direct use as an encryption key. It may be relatively short, predictable, or vulnerable to dictionary attacks.

age uses scrypt, a password-based key derivation function (KDF), to transform your passphrase into cryptographic key material.

How it works:

  1. You enter your passphrase.
  2. scrypt processes it using a salt and configurable computational and memory costs.
  3. It produces derived key material.
  4. That material is used to protect the file's encryption key.

Why scrypt?

Unlike a simple hash function, scrypt deliberately consumes computational resources and memory.

This makes large-scale password guessing more expensive, particularly for attackers using specialized hardware.

The important distinction is that scrypt protects against brute-force attacks on weak passphrases; it does not make a weak passphrase impossible to guess.

2. ChaCha20-Poly1305 — Encryption and authentication

Authenticated encryption

Once the encryption key is established, age uses ChaCha20-Poly1305, an authenticated encryption with associated data (AEAD) construction.

It combines two cryptographic mechanisms:

  • ChaCha20: Encrypts the actual data, making the original plaintext unreadable without the correct key.
  • Poly1305: Generates an authentication tag that allows the recipient to detect unauthorized modifications.

Why does this matter?

Encryption alone provides confidentiality, but authentication also helps protect integrity.

For example, if someone modifies the encrypted archive, the authentication check will detect the tampering during decryption.


3. How they work together

Your passphrase

Human-readable secret

↓

scrypt

Memory-hard key derivation

↓

Encryption key material

↓

ChaCha20-Poly1305

Encryption + authentication

↓

Authenticated encrypted data

Confidentiality and integrity protection

4. Does this affect encryption performance?

Yes, but in different ways.

Component

Performance impact

scrypt

Memory and CPU cost during key derivation

ChaCha20

CPU cost while encrypting/decrypting data

Poly1305

Additional authentication processing

tar + gzip

CPU and disk I/O overhead

An important distinction: scrypt is not repeatedly processing every file in your directory. Its main cost occurs during passphrase-based key derivation. For large archives, the time-consuming work is generally compression, disk I/O, and bulk encryption.

ChaCha20-Poly1305 is designed to be efficient, including on systems without dedicated AES acceleration.

5. Why age uses this combination

The design provides several useful security properties:

  • Resistance to large-scale passphrase guessing through memory-hard key derivation.
  • Strong confidentiality through authenticated encryption.
  • Detection of encrypted-data modification.
  • Efficient streaming encryption for large files and archives.

For additional technical reading:

scrypt makes deriving the encryption key from a guessed passphrase expensive; ChaCha20-Poly1305 protects the actual data and detects tampering. Together, they provide the cryptographic foundation for age's passphrase-based encryption.

We hope this was helpful.
Keep learning. Keep exploring. Build a safer open-source community.

Keep Us Caffeinated  ⦿ ⦿
Spotify Logo
↑
SNUBmonkey Join our readers