encryptcookie

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Next:      nil,
	Except:    []string{},
	Key:       "",
	Encryptor: EncryptCookie,
	Decryptor: DecryptCookie,
}

ConfigDefault is the default config

View Source
var ErrInvalidKeyLength = errors.New("encryption key must be 16, 24, or 32 bytes")

Functions

func DecryptCookie

func DecryptCookie(value, key string) (string, error)

DecryptCookie Decrypts a cookie value with specific encryption key

func EncryptCookie

func EncryptCookie(value, key string) (string, error)

EncryptCookie Encrypts a cookie value with specific encryption key

func GenerateKey

func GenerateKey(length int) string

GenerateKey returns a random string of 16, 24, or 32 bytes. The length of the key determines the AES encryption algorithm used: 16 bytes for AES-128, 24 bytes for AES-192, and 32 bytes for AES-256-GCM.

func New

func New(config ...Config) fiber.Handler

New creates a new middleware handler

Types

type Config

type Config struct {
	// Next defines a function to skip this middleware when returned true.
	//
	// Optional. Default: nil
	Next func(c fiber.Ctx) bool

	// Custom function to encrypt cookies.
	//
	// Optional. Default: EncryptCookie (using AES-GCM)
	Encryptor func(decryptedString, key string) (string, error)

	// Custom function to decrypt cookies.
	//
	// Optional. Default: DecryptCookie (using AES-GCM)
	Decryptor func(encryptedString, key string) (string, error)

	// Base64 encoded unique key to encode & decode cookies.
	//
	// Required. Key length should be 16, 24, or 32 bytes when decoded
	// if using the default EncryptCookie and DecryptCookie functions.
	// You may use `encryptcookie.GenerateKey(length)` to generate a new key.
	Key string

	// Array of cookie keys that should not be encrypted.
	//
	// Optional. Default: []
	Except []string
}

Config defines the config for middleware.

Jump to

Keyboard shortcuts

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