Standard library / crypto/cipher

crypto/cipher.NewCBCDecrypter()

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. CBC requires a block-sized IV (unpredictable for encryption) and complete blocks; no padding or authentication is supplied. For decryption use matching IV. Expected stdout: '00000000000000000000000000000000\n'.

Formal Syntax & Structure

go syntaxgo
func NewCBCDecrypter(b Block, iv []byte) BlockMode

Parameters & Attributes

NameTypeDescription
bBlockBlock cipher.
iv[]byteBlock-sized initialization vector.

Return Value

BlockMode

Stateful CBC mode instance.

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)  plain := make([]byte, 16)  encrypted := make([]byte, 16)  cipher.NewCBCEncrypter(b, iv).CryptBlocks(encrypted, plain)  cipher.NewCBCDecrypter(b, iv).CryptBlocks(plain, encrypted)  fmt.Printf("%x\n", plain)}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