crypto/aes

Guided tour · Crypto · pkg.go.dev →

The AES block cipher. Creates a cipher.Block you combine with a mode from crypto/cipher (GCM, CBC, CTR). Never use AES-ECB.

Construct the block cipher

NewCipher — key must be 16, 24, or 32 bytes

key := make([]byte, 32)   // AES-256
rand.Read(key)

block, err := aes.NewCipher(key)
if err != nil { log.Fatal(err) }

Pair with AES-GCM for authenticated encryption

Use AES-GCM (via crypto/cipher.NewGCM) unless you have an unusual reason not to. See the crypto/cipher page for the full example.