Standard library / crypto/cipher
crypto/cipher.NewGCMWithNonceSize()
Nonstandard nonce size for existing protocol interoperability only; prefer NewGCM. Nonce size must be positive. Public fixed key for an isolated test vector only; do not use it to protect real data. Expected stdout: '16 16\n'.
Formal Syntax & Structure
go syntaxgo
func NewGCMWithNonceSize(cipher Block, size int) (AEAD, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| cipher | Block | 128-bit block cipher, typically AES. |
| size | int | Required nonce size 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.NewGCMWithNonceSize(b, 16)) 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) }}