Standard library / crypto/aes
crypto/aes.NewCipher()
Accepts 16, 24 or 32 bytes (AES-128/192/256). Wrap the block with an authenticated mode. Public fixed key for an isolated test vector only; do not use it to protect real data. Expected stdout: '16\n'.
Formal Syntax & Structure
go syntaxgo
func NewCipher(key []byte) (cipher.Block, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| key | []byte | Key bytes of a supported length. |
Return Value
(cipher.Block, error)
Cipher instance, or an error for an invalid key length.
Working Example
Example Snippetgo
package main
import ( "crypto/aes" "fmt")
func main() { // Public known-answer test key only. Never protect real data with this key. b := must(aes.NewCipher(make([]byte, 16))) fmt.Println(b.BlockSize())}func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}