aes

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package aes contains the interfaces and implementations for encrypting and decrypting data.

Index

Constants

View Source
const KeyLength = 32

KeyLength is the key size this package accepts, in bytes. AES-256 is the only size offered: a configurable one invites a 16-byte key chosen by accident, and nothing here is short of entropy.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cipher

type Cipher struct {
	// contains filtered or unexported fields
}

Cipher is the AES-256-GCM encryption.Cipher implementation. It is exported, and returned by NewCipher, so a caller who has chosen AES-256-GCM can depend on that choice rather than on the interface every cipher shares.

func NewCipher

func NewCipher(key []byte, opts ...Option) (*Cipher, error)

NewCipher builds an AES-256-GCM Cipher over key.

The AEAD is constructed once here rather than per operation. Key schedule setup is not free, and doing it on every Encrypt was a per-row cost paid for nothing.

func (*Cipher) Open

func (e *Cipher) Open(ctx context.Context, ciphertext, associatedData []byte) ([]byte, error)

Open reverses Seal.

Every way of failing to authenticate collapses to encryption.ErrAuthenticationFailed: a tampered ciphertext, the wrong key, and associated data that does not match all produce the same GCM failure, and reporting which one it was would answer a question only an attacker is asking.

func (*Cipher) Seal

func (e *Cipher) Seal(ctx context.Context, plaintext, associatedData []byte) ([]byte, error)

Seal encrypts plaintext, authenticating associatedData alongside it.

The output is nonce || ciphertext || tag, unencoded. The previous surface base64'd its result because it returned a string; a []byte surface has nothing to escape, and a caller that needs text can encode once at the boundary that needs it rather than paying a third in size at rest.

type Option

type Option func(*options)

Option configures the encryptor this package constructs. The zero configuration works: an absent logger logs nowhere and an absent tracer provider traces nowhere.

func WithLogger

func WithLogger(logger logging.Logger) Option

WithLogger attaches a logger.

func WithTracerProvider

func WithTracerProvider(tracerProvider tracing.Provider) Option

WithTracerProvider attaches a tracer provider, enabling spans on every operation.

Jump to

Keyboard shortcuts

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