🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101

File encryption tool

Encrypt and decrypt files with a password using authenticated encryption and a proper key derivation function.

Intermediate⏱ 6–8 hoursđŸĒœ 7 stepsPythoncryptography

What you'll learn

  • ◆Symmetric encryption (AES-GCM / Fernet)
  • ◆Key derivation (scrypt/PBKDF2) and salts
  • ◆Why you never invent your own crypto

What you'll build

  • ✓encrypt file → file.enc with a password
  • ✓decrypt with the right password only
  • ✓Detects tampering
  • ✓Works for large files

Step-by-step guide

  1. 1

    Install

    pip install cryptography (do not write your own cipher).

  2. 2

    Derive a key

    Random 16-byte salt from os.urandom; derive a 32-byte key with Scrypt (or PBKDF2HMAC with many iterations).

  3. 3

    Encrypt

    AESGCM(key).encrypt(nonce, data, None) with a random 12-byte nonce; write salt + nonce + ciphertext.

  4. 4

    Decrypt

    Read salt and nonce, derive the key, decrypt; an InvalidTag exception means wrong password or tampered file.

  5. 5

    Large files

    Encrypt in chunks (each chunk with its own nonce and index) or use streaming with a library that supports it.

  6. 6

    Safe CLI

    Ask for the password with getpass (not as a command-line argument), confirm it twice.

  7. 7

    Explain

    README: what is protected, what is not (lost password = lost file).

🚀 Make it stand out

  • +Encrypt a whole folder into one archive
  • +GUI with Tkinter
  • +Public-key mode for sharing