crypto

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBcryptCost = 10

Variables

This section is empty.

Functions

func GenerateKeyPair added in v1.2.2

func GenerateKeyPair() (ed25519.PublicKey, ed25519.PrivateKey, error)

Types

type BcryptCrypto

type BcryptCrypto struct {
	Cost int
}

BcryptCrypto is the struct that holds the bcrypt crypto methods.

func NewBcryptCrypto

func NewBcryptCrypto(cost int) *BcryptCrypto

NewBcryptCrypto returns a new BcryptCrypto.

func (*BcryptCrypto) Hash

func (b *BcryptCrypto) Hash(password string) ([]byte, error)

Hash hashes a password using the bcrypt algorithm. password is the plaintext password to hash. Returns the hashed password, or an error on failure. The cost is set in the config file.

see: https://godoc.org/golang.org/x/crypto/bcrypt see: utils/config.go for the default cost.

func (*BcryptCrypto) Verify

func (*BcryptCrypto) Verify(password string, hash []byte) (bool, error)

Verify compares a bcrypt hashed password with its possible plaintext equivalent. password is the plaintext password to verify. hash is the bcrypt hashed password. Returns nil on success, or an error on failure. Returns true if the password matches, false if it does not.

type Crypto

type Crypto struct {
	Crypto ICrypto
}

Crypto is the struct that holds the crypto methods.

func (Crypto) Hash

func (c Crypto) Hash(password string) ([]byte, error)

Hash hashes a password using the configured crypto method password is the plaintext password to hash. Returns the hashed password, or an error on failure.

func (Crypto) Verify

func (c Crypto) Verify(password string, hash []byte) (bool, error)

Verify compares a crypto hashed password with its possible plaintext equivalent password is the plaintext password to verify. hash is the bcrypt hashed password. Returns nil on success, or an error on failure. Returns true if the password matches, false if it does not.

type HelperSingleton added in v1.2.2

type HelperSingleton struct {
	// contains filtered or unexported fields
}

HelperSingleton is the struct that holds the crypto helper.

func GetCryptoHelperInstance added in v1.2.2

func GetCryptoHelperInstance() *HelperSingleton

func (*HelperSingleton) GetCryptoHelper added in v1.2.2

func (c *HelperSingleton) GetCryptoHelper() Crypto

func (*HelperSingleton) SetCryptoHelper added in v1.2.2

func (c *HelperSingleton) SetCryptoHelper(crypto ICrypto)

type ICrypto

type ICrypto interface {
	// Hash hashes a password using the configured crypto method
	Hash(password string) ([]byte, error)
	// Verify compares a crypto hashed password with its possible plaintext equivalent
	Verify(password string, hash []byte) (bool, error)
}

ICrypto is the interface for the crypto methods It's used to abstract the crypto methods used in the application so that they can be easily swapped out if needed.

Jump to

Keyboard shortcuts

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