cookieguard

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Next:                   nil,
	Except:                 nil,
	Key:                    nil,
	Encryptor:              EncryptCookie,
	Decryptor:              DecryptCookie,
	EncryptKeys:            false,
	EncryptValues:          true,
	SuppressErrors:         false,
	SkipUnencryptedCookies: false,
}

ConfigDefault is the default config

Functions

func DecryptCookie

func DecryptCookie(data, key []byte) ([]byte, error)

DecryptCookie Decrypts a cookie data with specific encryption key

func EncryptCookie

func EncryptCookie(data, key []byte) ([]byte, error)

EncryptCookie Encrypts a cookie data with specific encryption key

func GenerateKey

func GenerateKey(length ...int) []byte

GenerateKey Generates an encryption key according to the length. If the length does not match the valid AES block size, it generates a 32-byte encryption key instead.

func New

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

New creates a new middleware handler

Types

type Config

type Config struct {
	// Array of cookie keys that should not be encrypted.
	//
	// Optional. Default: nil
	Except []string

	// Unique key to encode & decode cookies.
	//
	// Required. Key length should be 16, 24, or 32 characters.
	// You may use `encryptcookie.GenerateKey()` to generate a new key.
	Key []byte

	// 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
	Encryptor func(message, key []byte) ([]byte, error)

	// Custom function to decrypt cookies.
	//
	// Optional. Default: DecryptCookie
	Decryptor func(ciphertext, key []byte) ([]byte, error)

	// Encrypt cookie keys.
	//
	// Optional. Default: false
	EncryptKeys bool

	// Encrypt cookie values.
	//
	// Optional. Default: true
	EncryptValues bool

	// Suppress errors instead of panic on errors.
	//
	// Optional. Default: false
	SuppressErrors bool

	// Skip received cookies which are not encrypted.
	//
	// Optional. Default: false
	SkipUnencryptedCookies bool
	// contains filtered or unexported fields
}

Config defines the config for middleware.

Jump to

Keyboard shortcuts

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