Documentation
¶
Index ¶
- Constants
- Variables
- func CompareHashAndPassword(ctx context.Context, hash, password string) error
- func GenerateFromPassword(ctx context.Context, password string) (string, error)
- func GenerateOtp(digits int) (string, error)
- func GeneratePassword(requiredChars []string, length int) (string, error)
- func GenerateSignatures(secrets []string, msgID uuid.UUID, currentTime time.Time, inputPayload []byte) ([]string, error)
- func GenerateTokenHash(emailOrPhone, otp string) string
- func SecureToken(options ...int) string
- type Argon2HashInput
- type EncryptedString
- type FirebaseScryptHashInput
- type HashCost
Constants ¶
View Source
const ( // DefaultHashCost represents the default // hashing cost for any hashing algorithm. DefaultHashCost HashCost = iota // QuickHashCosts represents the quickest // hashing cost for any hashing algorithm, // useful for tests only. QuickHashCost HashCost = iota Argon2Prefix = "$argon2" FirebaseScryptPrefix = "$fbscrypt" FirebaseScryptKeyLen = 32 // Firebase uses AES-256 which requires 32 byte keys: https://pkg.go.dev/golang.org/x/crypto/scrypt#Key )
Variables ¶
View Source
var ErrArgon2MismatchedHashAndPassword = errors.New("crypto: argon2 hash and password mismatch")
View Source
var ErrScryptMismatchedHashAndPassword = errors.New("crypto: fbscrypt hash and password mismatch")
View Source
var PasswordHashCost = DefaultHashCost
PasswordHashCost is the current pasword hashing cost for all new hashes generated with GenerateHashFromPassword.
Functions ¶
func CompareHashAndPassword ¶
CompareHashAndPassword compares the hash and password, returns nil if equal otherwise an error. Context can be used to cancel the hashing if the algorithm supports it.
func GenerateFromPassword ¶
GenerateFromPassword generates a password hash from a password, using PasswordHashCost. Context can be used to cancel the hashing if the algorithm supports it.
func GenerateOtp ¶
GenerateOtp generates a random n digit otp
func GenerateSignatures ¶
func GenerateTokenHash ¶
Types ¶
type Argon2HashInput ¶
type Argon2HashInput struct {
// contains filtered or unexported fields
}
func ParseArgon2Hash ¶
func ParseArgon2Hash(hash string) (*Argon2HashInput, error)
type EncryptedString ¶
type EncryptedString struct {
KeyID string `json:"key_id"`
Algorithm string `json:"alg"`
Data []byte `json:"data"`
Nonce []byte `json:"nonce,omitempty"`
}
func NewEncryptedString ¶
func ParseEncryptedString ¶
func ParseEncryptedString(str string) *EncryptedString
func (*EncryptedString) IsValid ¶
func (es *EncryptedString) IsValid() bool
func (*EncryptedString) ShouldReEncrypt ¶
func (es *EncryptedString) ShouldReEncrypt(encryptionKeyID string) bool
ShouldReEncrypt tells you if the value encrypted needs to be encrypted again with a newer key.
func (*EncryptedString) String ¶
func (es *EncryptedString) String() string
type FirebaseScryptHashInput ¶
type FirebaseScryptHashInput struct {
// contains filtered or unexported fields
}
func ParseFirebaseScryptHash ¶
func ParseFirebaseScryptHash(hash string) (*FirebaseScryptHashInput, error)
See: https://github.com/firebase/scrypt for implementation
Click to show internal directories.
Click to hide internal directories.