← Back to Portfolio

Encrypted Journal: In‑Depth Tour

🔗 Overview & Dependencies

This application relies on the following Python modules and libraries (as imported at the top of secure_journal.py):

These imports establish the core functionality: GUI, secure key derivation & encryption, file I/O, spell‑checking, and optional platform‑specific enhancements.

Import list sourced from secure_journal.py fileciteturn1file3.

🎙️ Voice Overview

📊 Architecture & Data Flow

flowchart TD A["User enters text"] --> B["scrypt() derives key"] B --> C["AESGCM.encrypt(nonce, data)"] C --> D["Base64 encode and Gzip to journal.json.gz"] D --> E["Saved to disk with secure permissions"] E --> F["On load: reverse steps"]

💻 Code Walkthrough

1. Key Derivation (scrypt)

# derive a 32-byte key from the passphrase
kdf = Scrypt(
    salt=secrets.token_bytes(16),
    length=32,
    n=2**14, r=8, p=1,
)
key = kdf.derive(password.encode())
        

This uses Scrypt to turn your passphrase into a strong symmetric key.

2. Encryption (AES-GCM)

aesgcm = AESGCM(key)
nonce = secrets.token_bytes(12)
ciphertext = aesgcm.encrypt(nonce, message.encode(), None)
record = {
  "nonce": base64.b64encode(nonce).decode(),
  "entry": base64.b64encode(ciphertext).decode()
}
        

AES-GCM provides both confidentiality and integrity.

3. Compression & Storage

with gzip.open('journal.json.gz', 'wt', encoding='utf-8') as f:
    json.dump(data_list, f, indent=4)
        

Gzip shrinks the file and JSON ensures structured storage.

4. Loading & Decryption

with gzip.open('journal.json.gz', 'rt', encoding='utf-8') as f:
    data_list = json.load(f)
plaintext = aesgcm.decrypt(nonce, ciphertext, None).decode()
        

Reverses the write steps to retrieve your journal text.

5. GUI Interaction

All encryption calls are wrapped in GUI methods with proper password prompts and session timeouts.