Symmetric encryption

Handle nonces and associated data

Follow the library’s nonce requirements and authenticate unencrypted context such as record IDs, versions, and content types.

8 minute lesson

~~~

A nonce is not normally secret, but reuse can destroy security for common encryption constructions. Follow the exact API contract.

Prefer library-managed nonces. When you must provide one, generate or count it according to the construction and never reuse the same nonce with the same key. Associated data remains visible but is protected from undetected modification.

Two workers share an encryption key and each starts a nonce counter at zero after deployment. Their first messages reuse a nonce with the same key, breaking the construction assumptions.

Associated data can bind visible context such as a record ID and schema version. It prevents moving valid ciphertext to another record even though that context is not encrypted.

Use a library-managed nonce to encrypt two records and save the nonce, record ID, and schema version with each result. Swap the record IDs during decryption and prove authentication fails. Then simulate two workers or a counter restart and show how the design prevents nonce reuse under the same key.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →