ToolypetMCP
advanced5 minutessecurity

Encrypt, Decrypt & Verify

Full encryption lifecycle: generate key, encrypt data with AES, hash for integrity, and verify the pipeline.

aesencryptiondecryptionintegritypipeline

Cuándo usar esta receta

Demonstrates the full encrypt-then-MAC pattern for data protection. Essential understanding for implementing secure data storage and transmission.

Pasos

1

Create encryption key and IV

Indicación:Generate a 256-bit encryption key in hex and a 128-bit IV
2

Encrypt the sensitive data

Indicación:Encrypt 'Confidential: Q4 revenue was $2.3M' using AES-256-CBC with the generated key and IV
3

Create integrity checksum

Indicación:Generate SHA-256 hash of the ciphertext for integrity verification
4

Add authenticated integrity

Indicación:Generate HMAC-SHA256 of the ciphertext using a separate authentication key

Preguntas frecuentes

What is encrypt-then-MAC?

Encrypt the plaintext first, then compute a MAC (HMAC) over the ciphertext. The receiver verifies the MAC before decrypting, preventing padding oracle and other attacks.

Why not just use AES-GCM instead?

AES-GCM combines encryption and authentication in one step (AEAD). It is preferred over manual encrypt-then-MAC. This recipe demonstrates the concept; use GCM in production.

Recetas relacionadas