Standard library / crypto/cipher

crypto/cipher.StreamWriter.Close()

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. Close forwards to an underlying io.Closer when present; otherwise returns nil. No internal buffer to flush. Expected stdout: 'closed\n'.

Formal Syntax & Structure

go syntaxgo
func (w StreamWriter) Close() error

Return Value

error

Underlying close error, if any.

Working Example

Example Snippetgo
package main
import (  "bytes"  "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)  var buf bytes.Buffer  w := cipher.StreamWriter{S: cipher.NewCTR(b, iv), W: &buf}  check(w.Close())  fmt.Println("closed")}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