fernet

package
v1.0.4005 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(tok []byte, ttl time.Duration, k []*Key) (msg []byte)

Decrypt verifies that tok is a valid fernet token that was signed with a key in k at most ttl time ago only if ttl is greater than zero. Returns the message contained in tok if tok is valid, otherwise nil.

func DecryptWithTime

func DecryptWithTime(tok []byte, ttl time.Duration, k []*Key, now time.Time) (msg []byte)

DecryptWithTime verifies that tok is a valid fernet token that was signed with a key in k at most ttl time ago only if ttl is greater than zero. Returns the message contained in tok if tok is valid, otherwise nil.

func Encrypt

func Encrypt(msg []byte, k *Key) (tok []byte, err error)

Encrypt encrypts and signs msg with key k and returns the resulting fernet token. If msg contains text, the text should be encoded with UTF-8 to follow fernet convention.

func EncryptWithTime

func EncryptWithTime(msg []byte, k *Key, encryptAt time.Time) (tok []byte, err error)

EncryptWithTime encrypts and signs msg with key k at timestamp encryptAt and returns the resulting fernet token. If msg contains text, the text should be encoded with UTF-8 to follow fernet convention.

Types

type Key

type Key struct {
	Value [32]byte
}

Key represents a key.

func DecodeKey

func DecodeKey(s string) (*Key, error)

DecodeKey decodes a key from s and returns it. The key can be in hexadecimal, standard base64, or URL-safe base64.

func DecodeKeys

func DecodeKeys(k ...string) ([]*Key, error)

DecodeKeys decodes each element of k using DecodeKey and returns the resulting keys. Requires at least one key.

func GenerateKey

func GenerateKey() *Key

Generate initializes k with pseudorandom data from package crypto/rand.

func NewKey

func NewKey(k []byte) (*Key, error)

func (*Key) Encode

func (k *Key) Encode() string

Encode returns the URL-safe base64 encoding of k.

func (*Key) Generate

func (k *Key) Generate() error

Generate initializes k with pseudorandom data from package crypto/rand.

Jump to

Keyboard shortcuts

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