Standard library / crypto/cipher
crypto/cipher.Stream
Legacy interoperability only; this mode provides no authentication. Prefer AEAD for new designs. Fixed key and IV below are public test fixtures, never deployment values. XORKeyStream advances state across calls, requires sufficient dst and exact or no overlap. Create a fresh matching stream to reverse encryption. Expected stdout: 'Go\n'.
Formal Syntax & Structure
go syntaxgo
type Stream interface { XORKeyStream(dst, src []byte)}Working Example
Example Snippetgo
package main
import ( "crypto/aes" "crypto/cipher" "fmt")
func main() { // Historical interoperability demonstration only. Never deploy this cipher/mode. b := must(aes.NewCipher(make([]byte, 16))) iv := make([]byte, 16) p := []byte("Go") enc := make([]byte, len(p)) var s cipher.Stream = cipher.NewCTR(b, iv) s.XORKeyStream(enc, p) cipher.NewCTR(b, iv).XORKeyStream(p, enc) fmt.Println(string(p))}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) }}