encryption

package
v7.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	CodeChallengeMethodPlain = "plain"
	CodeChallengeMethodS256  = "S256"
)

Variables

This section is empty.

Functions

func CheckNonce added in v7.1.3

func CheckNonce(nonce []byte, hashed string) bool

CheckNonce tests if a nonce matches the hashed version of it

func GenerateCodeChallenge added in v7.3.0

func GenerateCodeChallenge(method, codeVerifier string) (string, error)

func GenerateCodeVerifierString added in v7.8.0

func GenerateCodeVerifierString(n int) (string, error)

GenerateCodeVerifierString returns a base64 encoded string of n random bytes

func HashNonce added in v7.1.3

func HashNonce(nonce []byte) string

HashNonce returns the SHA256 hash of a nonce

func Nonce

func Nonce(length int) ([]byte, error)

Nonce generates a random n-byte slice

func SecretBytes

func SecretBytes(secret string) []byte

SecretBytes attempts to base64 decode the secret, if that fails it treats the secret as binary

func SignedValue

func SignedValue(seed string, key string, value []byte, now time.Time) (string, error)

SignedValue returns a cookie that is signed and can later be checked with Validate

func Validate

func Validate(cookie *http.Cookie, seed string, expiration time.Duration) (value []byte, t time.Time, ok bool)

Validate ensures a cookie is properly signed

Types

type Cipher

type Cipher interface {
	Encrypt(value []byte) ([]byte, error)
	Decrypt(ciphertext []byte) ([]byte, error)
}

Cipher provides methods to encrypt and decrypt

func NewBase64Cipher

func NewBase64Cipher(c Cipher) Cipher

NewBase64Cipher returns a new AES Cipher for encrypting cookie values and wrapping them in Base64 -- Supports Legacy encryption scheme

func NewCFBCipher

func NewCFBCipher(secret []byte) (Cipher, error)

NewCFBCipher returns a new AES CFB Cipher

func NewGCMCipher

func NewGCMCipher(secret []byte) (Cipher, error)

NewGCMCipher returns a new AES GCM Cipher

Jump to

Keyboard shortcuts

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