7.7. Symmetric Encryption¶
Functions:
-
SymEnc
(key []byte, iv []byte, plaintext []byte) ([]byte)¶ Encrypt the plaintext using AES-CTR mode with the provided key and IV.
Returns the ciphertext, which will contain the IV (you do not need to store the IV separately).
This function is capable of encrypting variable-length plaintext, regardless of size. You do NOT need to pad your plaintext to any specific block size.
- Parameters
key ([]byte) – 16-byte symmetric key for encryption
iv ([]byte) – 16-byte initialization vector
plaintext ([]byte) – Message to encrypt
- Returns
Ciphertext
- Return type
[]byte
-
SymDec
(key []byte, ciphertext []byte) ([]byte)¶ Decrypt the ciphertext using the key.
- Parameters
key ([]byte) – 16-byte symmetric key for decryption
ciphertext ([]byte) – Message to decrypt
- Returns
Plaintext
- Return type
[]byte
Warning
Remember: one key, one purpose. If we use a key for HKDF or HMAC, we should not use the same key for symmetric encryption.