Standard library / crypto/cipher

crypto/cipher.NewCFBEncrypter()

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. CFB is deprecated in newer Go documentation and uses an unpredictable block-sized IV. Stateful stream processes arbitrary byte counts. Expected stdout: 'Go\n'.

Formal Syntax & Structure

go syntaxgo
func NewCFBEncrypter(block Block, iv []byte) Stream

Parameters & Attributes

NameTypeDescription
blockBlockUnderlying block cipher.
iv[]byteBlock-sized IV or initial counter.

Return Value

Stream

Stateful cipher stream.

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))  cipher.NewCFBEncrypter(b, iv).XORKeyStream(enc, p)  cipher.NewCFBDecrypter(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)  }}
Go Reference