Documentation ¶
Index ¶
Constants ¶
const AES256KeySize = 32
AES256KeySize key size for AES-256
Variables ¶
var ( ErrHashMissmatch = errors.New("hashes do not match") ErrInvalidKey = errors.New("invalid key") )
Common errors
var (
ErrToShortCiphertext = errors.New("ciphertext too short")
)
Common encryption / decryption errors.
Functions ¶
func GenerateAESKey ¶
GenerateAESKey generates a random AES-256 key.
func RandomBytes ¶
RandomBytes generates an array of n random bytes.
Types ¶
type AESCipher ¶
type AESCipher struct {
// contains filtered or unexported fields
}
AESCipher symetric cipher implementation using AES-GCM.
func NewAESCipher ¶
NewAESCipher creates a new AES-GCM cipher with the given key.
type Argon2Hasher ¶
type Argon2Hasher struct {
// contains filtered or unexported fields
}
Argon2Hasher hasher implementation using the Argon2id key derivation function.
func (*Argon2Hasher) Hash ¶
func (h *Argon2Hasher) Hash(plaintext, salt []byte) ([]byte, error)
Hash derives a key using Argon2id.
func (*Argon2Hasher) Verify ¶
func (h *Argon2Hasher) Verify(plaintext, salt, hashtext []byte) error
Verify verifies that the plaintext and salt hash to the given hashtext.
type Cipher ¶
type Cipher interface { Encrypt(plaintext []byte) ([]byte, error) Decrypt(ciphertext []byte) ([]byte, error) }
Cipher symetric chipher interface.
type Hasher ¶
type Hasher interface { Hash(plaintext, salt []byte) ([]byte, error) Verify(plaintext, salt, hashtext []byte) error }
Hasher interface for hashing and verifying hased values.
func DefaultArgon2Hasher ¶
func DefaultArgon2Hasher() Hasher
func DefaultScryptHasher ¶
func DefaultScryptHasher() Hasher
DefaultScryptHasher creates scrypt hasher with the default key parameters
func NewArgon2Hasher ¶
NewArgon2Hasher creates a new Argon2id hasher
func NewScryptHasher ¶
NewScryptHasher creates a new scrypt hasher
type ScryptHasher ¶
type ScryptHasher struct {
// contains filtered or unexported fields
}
ScryptHasher hasher implementation using the SCRYPT key derivation function.
func (*ScryptHasher) Verify ¶
func (h *ScryptHasher) Verify(plaintext, salt, hashtext []byte) error
Verify verifies that plaintext and salt hash to the given hashtext.
type Sha256Hasher ¶
type Sha256Hasher struct{}
Sha256Hasher hasher implementation using sha256 as a hash function.
func (*Sha256Hasher) Hash ¶
func (h *Sha256Hasher) Hash(plaintext, salt []byte) ([]byte, error)
Hash computes hmac of plaintext and salt and calculates a SHA-256 hash on the output.
func (*Sha256Hasher) Verify ¶
func (h *Sha256Hasher) Verify(plaintext, salt, hashtext []byte) error
Verify verifies that plaintext and salt hash to the given hashtext.