crypto

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package crypto provides AES-GCM encryption for secrets at rest and HMAC signing for session cookies. The key is derived from the configured secret.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cipher

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

Cipher wraps a key derived from the app secret.

func New

func New(secret string) *Cipher

New derives a 256-bit key from the given secret via SHA-256.

func (*Cipher) Decrypt

func (c *Cipher) Decrypt(encoded string) ([]byte, error)

Decrypt reverses Encrypt.

func (*Cipher) Encrypt

func (c *Cipher) Encrypt(plaintext []byte) (string, error)

Encrypt seals plaintext with AES-256-GCM and returns base64(nonce||ciphertext).

func (*Cipher) Sign

func (c *Cipher) Sign(msg []byte) string

Sign returns base64(HMAC-SHA256(msg)).

func (*Cipher) Verify

func (c *Cipher) Verify(msg []byte, sig string) bool

Verify checks an HMAC produced by Sign in constant time.

Jump to

Keyboard shortcuts

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