Documentation
¶
Overview ¶
Package securehash provides a secure and easy way to hash and compare secrets. It supports bcrypt and argon2 as hashing algorithms and can be used to upgrade hashes over time as security best practices change.
A SecureHasher is created with a specific algorithm and its parameters. It can then be used to hash new secrets or compare existing hashes with a plaintext secret. When comparing, it will also indicate if the hash needs to be upgraded to the current configuration.
The Hash type represents a hashed secret and can be marshaled to and unmarshaled from text for easy storage.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Argon2Options ¶
type Argon2Options struct {
// contains filtered or unexported fields
}
Argon2Options hold hashing options for a Argon2ID key
func Argon2 ¶
func Argon2() *Argon2Options
Argon2 initializes argon2 with Owasp recommended settings.
type BcryptOptions ¶
type BcryptOptions struct {
// contains filtered or unexported fields
}
BcryptOptions hold options for generating a bcrypt hash
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
Hash represents a hashed secret.
func (*Hash) DecodeSpanner ¶
DecodeSpanner implements the spanner.Decoder interface
func (Hash) EncodeSpanner ¶
EncodeSpanner implements the spanner.Encoder interface
func (*Hash) MarshalText ¶
MarshalText implements encoding.TextMarshaler for storing a hashed secret.
func (*Hash) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler for loading a secret from storage
type HashAlgorithm ¶
type HashAlgorithm interface {
// contains filtered or unexported methods
}
HashAlgorithm is used to specify a configuration for a new SecureHasher.
type SecureHasher ¶
type SecureHasher struct {
// contains filtered or unexported fields
}
SecureHasher is used for deriving and comparing
func New ¶
func New(algo HashAlgorithm) *SecureHasher
New configures a SecureHasher using the provided initialization function.
func (*SecureHasher) Compare ¶
func (s *SecureHasher) Compare(hash *Hash, plaintext string) (bool, error)
Compare compares a key of any supported type and a plaintext secret. It returns an error if they do not match, and a boolean indicating if the key needs to be upgraded(rehashed) with the current configuration.
func (*SecureHasher) Hash ¶
func (s *SecureHasher) Hash(plaintext string) (*Hash, error)
Hash builds and returns a hashed and safe to store key based off the provided plaintext input.
func (*SecureHasher) KeyType ¶ added in v0.0.4
func (s *SecureHasher) KeyType() string
KeyType returns the underlying key type