Link Search Menu Expand Document

6.7 Symmetric Encryption


SymEnc(key []byte, iv []byte, plaintext []byte) (ciphertext []byte)

Encrypt the plaintext using AES-CTR mode with the provided 16-byte 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.

key ([]byte) - a 16-byte symmetric key for encryption
iv ([]byte) - a 16-byte initialization vecvtor
plaintext ([]byte) - message to encrypt

ciphertext ([]byte)

SymDec(key []byte, ciphertext []byte) (plaintext []byte)

Decrypt the ciphertext using the 16-byte key.

If the provided ciphertext is less than the length of one cipher block, then SymDec will panic.

key ([]byte) - a 16-byte symmetric key for decryption
ciphertext (uint32) - message to decrypt

plaintext ([]byte)
Notice that the SymDec method does not return an error. In other words, if some ciphertext has been mutated, SymDec will return non-useful plaintext (e.g. garbage), since AES-CTR mode does not provide integrity.