crypto

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MinHMACKeyBytes = 16

MinHMACKeyBytes is the floor for supplied HMAC signing secrets; generated ones 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 DecryptAESGCMAAD

func DecryptAESGCMAAD(encoded string, key, aad []byte) ([]byte, error)

DecryptAESGCMAAD reverses EncryptAESGCMAAD.

func DeriveKey

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

DeriveKey is HKDF-SHA256(master, no salt, label) to 32 bytes, the convention internal/drive uses, so a value sealed for one purpose never opens under another. Stored data depends on the exact output: never change it.

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 EncryptAESGCMAAD

func EncryptAESGCMAAD(plaintext, key, aad []byte) (string, error)

EncryptAESGCMAAD is EncryptAESGCM authenticating aad too; decrypting needs the same aad.

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