crypto

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MinHMACKeyBytes = 16

MinHMACKeyBytes is the imported signing-key floor; generated keys use 32 bytes.

Variables

View Source
var ErrCiphertextTooShort = errors.New("crypto: ciphertext too short")

ErrCiphertextTooShort reports a payload shorter than the AES-GCM nonce it must start with.

View Source
var ErrKeyLength = errors.New("crypto: AES-256-GCM key must be exactly 32 bytes")

ErrKeyLength reports an AES-256-GCM key that is not exactly 32 bytes.

Functions

func ComputeHMACSHA256

func ComputeHMACSHA256(data []byte, secret string) string

ComputeHMACSHA256 computes HMAC-SHA256 hex string.

func DecryptAESGCM

func DecryptAESGCM(encoded string, key []byte) ([]byte, error)

DecryptAESGCM reverses EncryptAESGCM.

func DeriveKey

func DeriveKey(master []byte, label string) []byte

DeriveKey derives a 32-byte key from master for one specific use, so a value encrypted under one derived key never decrypts under another even if master is shared.

func EncryptAESGCM

func EncryptAESGCM(plaintext, key []byte) (string, error)

EncryptAESGCM encrypts plaintext with AES-256-GCM under a 32-byte key and a random 12-byte nonce, returning nonce||ciphertext as raw base64url.

func GeneratePKCE

func GeneratePKCE() (verifier string, challenge string, err error)

GeneratePKCE creates a PKCE code_verifier and code_challenge (S256).

func RandomBase64URL

func RandomBase64URL(n int) string

RandomBase64URL generates a cryptographically secure URL-safe base64 string.

func RandomHex

func RandomHex(n int) string

RandomHex generates a cryptographically secure random hex string of 2*n characters.

func SHA256Hex

func SHA256Hex(data []byte) string

SHA256Hex returns the hex-encoded SHA-256 digest of input.

func VerifyHMACSHA256

func VerifyHMACSHA256(data []byte, secret, expectedHex string) bool

VerifyHMACSHA256 verifies HMAC-SHA256 signature in constant time.

Types

This section is empty.

Jump to

Keyboard shortcuts

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