aead

package
v0.0.0-...-b87464d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: Apache-2.0, MIT Imports: 2 Imported by: 0

Documentation

Overview

Package aead provides an implementation of Authenticated Encryption with Associated Data (AEAD) using the Newplex protocol.

Example
package main

import (
	"fmt"

	"github.com/codahale/newplex/aead"
)

func main() {
	key := []byte("a very secret key, 32 bytes long")
	nonce := []byte("a 16-byte nonce!")
	ad := []byte("some additional data")
	plaintext := []byte("hello world")

	// Create a new AEAD instance with a 16-byte nonce.
	c := aead.New("com.example.aead", key, 16)

	// Seal the plaintext.
	ciphertext := c.Seal(nil, nonce, plaintext, ad)
	fmt.Printf("ciphertext = %x\n", ciphertext)

	// Open the ciphertext.
	decrypted, err := c.Open(nil, nonce, ciphertext, ad)
	if err != nil {
		panic(err)
	}
	fmt.Printf("plaintext  = %s\n", decrypted)

}
Output:

ciphertext = 5cbd82ac3cdc5b1c7c0fc1a0f969533d51081739379e6e500cfbeb
plaintext  = hello world

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(domain string, key []byte, nonceSize int) cipher.AEAD

New returns a new cipher.AEAD instance which uses the given domain string and key.

Panics if nonceSize is less than 16 bytes. A minimum of 16 bytes is required to ensure sufficient uniqueness and security for the nonce values.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL