cryptography

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BcryptDefaultCost = bcrypt.DefaultCost
	BcryptMaxCost     = bcrypt.MaxCost
	BcryptMinCost     = bcrypt.MinCost
)

Variables

This section is empty.

Functions

func DecryptAES256GCM

func DecryptAES256GCM(text, key []byte) ([]byte, error)

Decrypt data with AES-256-GCM algorithm, like `AES256GCM.Decrypt()` but fully functional

func EncryptAES256GCM

func EncryptAES256GCM(text, key []byte) ([]byte, error)

Encrypt data with AES-256-GCM algorithm, like `AES256GCM.Encrypt()` but fully functional

Types

type AES256GCM

type AES256GCM interface {
	// Encrypt data with AES-256-GCM algorithm
	Encrypt(text []byte) ([]byte, error)

	// Decrypt data with AES-256-GCM algorithm
	Decrypt(text []byte) ([]byte, error)
}

func NewAES256GCM

func NewAES256GCM(key []byte) AES256GCM

Create new encrypt/decrypt with AES-256-GCM algoritm

type Argon2

type Argon2 interface {
	// Hash text with argon2 algorithm with format from `hashFormat` or you can determine your specific format
	Hash(text []byte) (string, error)

	// Compare plain text with hash argon2, return `true“ and error `nil` if equal
	Compare(text, hashedText []byte) (bool, error)

	// Set memory for argon2 parameter
	SetMemory(memory uint32) Argon2

	// Set iterations for argon2 parameter
	SetIterations(iterations uint32) Argon2

	// Set parallelism for argon2 parameter
	SetParallelism(parallelism uint8) Argon2
}

func NewArgon2

func NewArgon2() Argon2

Create argon2 hash with default parameter. Compatible with nodejs library `https://github.com/ranisalt/node-argon2.git` if you set `memory = 65536` and `parallelism = 4` because default parameter of my lib is `memory = 4096` and `parallelism = 1`

type Bcrypt

type Bcrypt interface {
	// Hash plain text with bcrypt algoritm
	Hash(plainText []byte) ([]byte, error)

	// Compare plain text with hashed text with bcrypt algorithm
	Compare(plainText, hashedText []byte) error

	// Set cost of bcrypt algoritm. By default using `cryptography.BcryptDefaultCost`
	SetCost(cost int) Bcrypt

	// Get cost used of this bcrypt algoritm
	GetCost() int

	// Count cost value from hashed text with bcrypt algorithm. This method will not set `cost` of existing bcrypt
	CostFromHash(hashedText []byte) (int, error)
}

func NewBcrypt

func NewBcrypt() Bcrypt

Create new bcrypt based on `golang.org/x/crypto/bcrypt` with default `cost` using `cryptography.BcryptDefaultCost`

type SHA256

type SHA256[T any] interface {
	// Added key to hash SHA-256
	WithKey(key []byte) *T

	// Generate SHA-256 string value from `text` and return error with code `codes.CodeInvalidValue` if generate is failed
	Build() (string, error)
}

func NewSHA256

func NewSHA256(text []byte) SHA256[sha256impl]

Create hash with SHA-256 algoritm

Jump to

Keyboard shortcuts

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