Cipher.initialize

void initialize(CipherOperation op, SecretKey key, const(ubyte)[] iv)

Initializes the cipher with a key and IV/nonce.

The IV is a mandatory parameter by design: for nonce-based modes (CTR, GCM, ChaCha20-Poly1305) reusing an IV with the same key is catastrophic — it reveals plaintext relationships and (in AEAD modes) the authentication key. Callers must generate a fresh, unique nonce per encryption; a random 96-bit nonce is the common safe choice.

Passing null is legal only for modes that genuinely take no IV (e.g. ECB); implementations MUST throw CryptoException when a required IV is missing.

Parameters

opThe operation mode (encryption or decryption).
keyThe secret key; a typed SecretKey so a public/private key cannot be passed where a symmetric key is required.
ivThe initialization vector or nonce; never reuse one with the same key.

Throws

CryptoException when the mode requires an IV and iv is null,

or the key/IV length is invalid for this cipher.