token

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package token provides secure opaque token generation and lookup hashing.

Index

Constants

View Source
const (

	// MinLookupKeyBytes is the minimum application-controlled HMAC key length
	// for token lookup hashes.
	MinLookupKeyBytes = 32
)

Variables

View Source
var (
	// ErrInvalidLength reports an unsafe token byte length.
	ErrInvalidLength = errors.New("token: invalid length")

	// ErrEmptyToken reports that a token value was empty.
	ErrEmptyToken = errors.New("token: empty token")

	// ErrWeakLookupKey reports that an HMAC lookup key is too short.
	ErrWeakLookupKey = errors.New("token: weak lookup key")
)

Functions

func GenerateAPIKeySecret

func GenerateAPIKeySecret() (string, error)

GenerateAPIKeySecret returns a URL-safe opaque API key secret.

func GenerateOpaque

func GenerateOpaque(byteLength int) (string, error)

GenerateOpaque returns a URL-safe opaque value with at least 128 bits of entropy.

func GeneratePublicID

func GeneratePublicID() (string, error)

GeneratePublicID returns a URL-safe public identifier.

func HMACLookupHash

func HMACLookupHash(value string, key []byte) ([]byte, error)

HMACLookupHash returns an HMAC-SHA-256 lookup hash for a high-entropy random token using an application-controlled lookup key.

func LookupHash

func LookupHash(value string) ([]byte, error)

LookupHash returns a SHA-256 lookup hash for a high-entropy random token.

This is appropriate for high-entropy API keys generated by this package. It is not suitable for human passwords.

Types

This section is empty.

Jump to

Keyboard shortcuts

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