secretbox

package
v0.0.0-...-9204231 Latest Latest
Warning

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

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

Documentation

Overview

Package secretbox provides authenticated symmetric encryption (AES-256-GCM) for secrets stored at rest (e.g. per-shop Telegram bot tokens).

Index

Constants

View Source
const KeySize = 32

KeySize is the required AES-256 key length in bytes.

Variables

View Source
var ErrInvalidKey = errors.New("secretbox: key must be 32 bytes")

ErrInvalidKey is returned when the key is not KeySize bytes.

Functions

This section is empty.

Types

type Box

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

Box seals and opens secrets with AES-256-GCM, and derives deterministic HMAC tags (for equality/uniqueness checks over encrypted-at-rest values).

func New

func New(key []byte) (*Box, error)

New returns a Box for the given 32-byte key.

func (*Box) HMAC

func (b *Box) HMAC(s string) string

HMAC returns a deterministic hex HMAC-SHA256 tag of s. Unlike Seal (random nonce → different ciphertext each call), HMAC yields the same tag for the same input, so it can back a UNIQUE index for detecting duplicate secrets without storing plaintext.

func (*Box) Open

func (b *Box) Open(encoded string) (string, error)

Open decrypts a value produced by Seal.

func (*Box) Seal

func (b *Box) Seal(plaintext string) (string, error)

Seal encrypts plaintext and returns base64(nonce ‖ ciphertext).

Jump to

Keyboard shortcuts

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