Standard library / crypto/cipher
crypto/cipher.Block
Single-block primitive: BlockSize gives required length, Encrypt and Decrypt transform the first block; src and dst must fully overlap or not overlap. Not a complete message encryption scheme. Public fixed key for an isolated test vector only; do not use it to protect real data. Expected stdout: '66e94bd4ef8a2c3b884cfa59ca342b2e\n'.
Formal Syntax & Structure
go syntaxgo
type Block interface { BlockSize() int
Encrypt(dst, src []byte)
Decrypt(dst, src []byte)}Working Example
Example Snippetgo
package main
import ( "crypto/aes" "crypto/cipher" "fmt")
func main() { // Public known-answer test key only. Never protect real data with this key. var b cipher.Block = must(aes.NewCipher(make([]byte, 16))) dst := make([]byte, 16) b.Encrypt(dst, make([]byte, 16)) fmt.Printf("%x\n", dst)}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) }}