security

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCipherConfig = CipherConfig{
	Cipher: "AES-128-CBC",
	AllowedCiphers: map[string][]int{
		"AES-128-CBC": {16, 16},
		"AES-192-CBC": {16, 24},
		"AES-256-CBC": {16, 32},
	},
	KdfHash:              "sha256",
	MacHash:              "sha256",
	AuthKeyInfo:          "AuthorizationKey",
	DerivationIterations: 100000,
}

DefaultCipherConfig is the default cipher configuration

Functions

func Decrypt

func Decrypt(data, secret string, passwordBased bool, config CipherConfig) (string, error)

Decrypt decrypts data using a password or a key

func Encrypt

func Encrypt(data, secret string, passwordBased bool, config CipherConfig) (string, error)

Encrypt encrypts data using a password or a key

func GenerateRandomBytes

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

GenerateRandomBytes generates random bytes of specified length

func PasswordHash

func PasswordHash(password string, cost int) (string, error)

PasswordHash generates a hash of the password

func PasswordVerify

func PasswordVerify(password, hash string) bool

PasswordVerify validates the password against a given hash

Types

type AES

type AES struct {
	Text string `json:"text" default:""`
	Key  string `json:"key" default:"jcbase.aes_key__"`
	Iv   string `json:"iv" default:"jcbase.aes_iv___"`
}

func (AES) Decrypt

func (a AES) Decrypt(plaintext *string) error

Decrypt decrypts the given cipherText using the provided key and iv

func (AES) Encrypt

func (a AES) Encrypt(cipherText *string) error

Encrypt encrypts the given text using the provided key and iv

type CipherConfig

type CipherConfig struct {
	Cipher               string
	AllowedCiphers       map[string][]int
	KdfHash              string
	MacHash              string
	AuthKeyInfo          string
	DerivationIterations int
}

CipherConfig stores the cipher configuration

Jump to

Keyboard shortcuts

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