fernetutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 10 Imported by: ? 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

This section is empty.

Variables

View Source
var ErrExpiredToken = fmt.Errorf("%w: expired", ErrInvalidToken)

Error of a token older than the time to live it was checked against, also matching ErrInvalidToken

View Source
var ErrInvalidKey = errors.New("fernet key must be 32 bytes of padded url-safe base64")

Error of a key that is not 32 bytes in padded url-safe base64

View Source
var ErrInvalidToken = errors.New("invalid fernet token")

Error of every token that is malformed, forged, signed with another key or badly padded

Functions

func GenerateKey

func GenerateKey() []byte

New key of 32 random bytes in padded url-safe base64

Types

type Fernet

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

Token encrypter and decrypter over one key, safe for concurrent use

func New

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

Fernet over a key in padded url-safe base64, ErrInvalidKey for anything else

func (*Fernet) Decrypt

func (f *Fernet) Decrypt(token []byte) ([]byte, error)

Plaintext of a token whatever its age, ErrInvalidToken for every token that does not verify and decrypt

func (*Fernet) DecryptTTL

func (f *Fernet) DecryptTTL(token []byte, ttl time.Duration) ([]byte, error)

Plaintext of a token stamped no longer than ttl ago and not more than a minute ahead of the clock, ErrExpiredToken past the ttl; a ttl that is not positive checks no age

func (*Fernet) Encrypt

func (f *Fernet) Encrypt(data []byte) []byte

Token of data stamped with the current time under a random IV

Jump to

Keyboard shortcuts

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