Standard library / crypto/cipher

crypto/cipher.NewGCMWithTagSize()

Nonstandard authentication tag length for interoperability only. Accepts 12–16 bytes; prefer full 16-byte tags. Public fixed key for an isolated test vector only; do not use it to protect real data. Expected stdout: '12 12\n'.

Formal Syntax & Structure

go syntaxgo
func NewGCMWithTagSize(cipher Block, tagSize int) (AEAD, error)

Parameters & Attributes

NameTypeDescription
cipherBlock128-bit block cipher, typically AES.
tagSizeintAuthentication tag length in bytes.

Return Value

(AEAD, error)

Authenticated encryption instance, or invalid configuration error.

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.  b := must(aes.NewCipher(make([]byte, 16)))  g := must(cipher.NewGCMWithTagSize(b, 12))  fmt.Println(g.NonceSize(), g.Overhead())}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