Cipherbox AES-256 encryption for text

Encrypted message

Message anatomy

Every byte of the encrypted message is broken down here once there is one.

    How it works

    Keys

    A passphrase is stretched into a 256-bit key with PBKDF2-HMAC-SHA256 and a random 16-byte salt. The salt and iteration count are stored in the message, so the recipient only needs the passphrase.

    A raw key is used as is. Generate one here and share it once over a channel you trust; it is the whole secret.

    Modes

    GCM encrypts and authenticates, so a wrong key or a single altered byte makes decryption fail loudly. Use it unless another system expects something else.

    CBC and CTR are here for compatibility. They hide the text but cannot prove it arrived unchanged.

    Privacy

    Encryption runs in this tab through your browser's built-in Web Crypto API. The page's Content-Security-Policy forbids it from making network requests, so your text and keys have nowhere to go. Nothing is saved except your display preferences.

    Message format and decrypting elsewhere
    BytesFieldValue
    1Version1
    1Mode1 GCM, 2 CBC, 3 CTR
    1Key type0 raw key, 1 passphrase
    4IterationsPBKDF2 rounds, big-endian. Passphrase messages only.
    16SaltRandom. Passphrase messages only.
    12 or 16IV12-byte nonce for GCM; 16 bytes for CBC and CTR
    nCiphertextCBC adds PKCS#7 padding. GCM appends a 16-byte tag.

    GCM authenticates every byte before the IV as additional data. CTR counts with the full 128-bit block, the same as OpenSSL. Passphrases are encoded as UTF-8 exactly as typed. Here is a GCM passphrase message decrypted in Python with the cryptography package:

    import base64, struct
    from cryptography.hazmat.primitives import hashes
    from cryptography.hazmat.primitives.ciphers.aead import AESGCM
    from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
    
    def decrypt(message: str, passphrase: str) -> str:
        data = base64.b64decode(message)
        assert data[:3] == bytes([1, 1, 1]), "expects version 1, GCM, passphrase"
        iterations = struct.unpack(">I", data[3:7])[0]
        salt, nonce, body = data[7:23], data[23:35], data[35:]
        key = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32,
                         salt=salt, iterations=iterations).derive(passphrase.encode())
        return AESGCM(key).decrypt(nonce, body, data[:23]).decode()