Documentation ¶
Overview ¶
Package bcrypt implements Provos and Mazières's bcrypt adaptive hashing algorithm. See http://www.usenix.org/event/usenix99/provos/provos.pdf
Index ¶
- Constants
- Variables
- func Base64Decode(src []byte) ([]byte, error)
- func Base64Encode(src []byte) []byte
- func CompareHashAndPassword(hashedPassword, password []byte) error
- func Cost(hashedPassword []byte) (int, error)
- func DecodeSecret(secret []byte) (salt, key []byte)
- func GenerateFromPassword(password []byte, cost int) ([]byte, error)
- func GenerateFromPasswordSalt(password, salt []byte, cost int) ([]byte, error)
- func Key(password, salt []byte, cost int) ([]byte, error)
- func NewSalt() (salt []byte, err error)
- type HashVersionTooNewError
- type InvalidCostError
- type InvalidHashPrefixError
- type InvalidSaltSizeError
Constants ¶
const ( MinCost int = 4 // the minimum allowable cost as passed in to GenerateFromPassword MaxCost int = 31 // the maximum allowable cost as passed in to GenerateFromPassword DefaultCost int = 10 // the cost that will actually be set if a cost below MinCost is passed into GenerateFromPassword EncodedSaltSize = 22 EncodedHashSize = 31 )
Variables ¶
var ( // ErrMismatchedHashAndPassword is the error returned from CompareHashAndPassword when a password and hash do // not match. ErrMismatchedHashAndPassword = errors.New("github.com/go-crypt/x/bcrypt: the provided password is not a match for the provided hashed password") // ErrHashTooShort is the error returned from CompareHashAndPassword when a hash is too short to // be a bcrypt hash. ErrHashTooShort = errors.New("github.com/go-crypt/x/bcrypt: hashed secret key is too short to be a bcrypt hashed secret key") // ErrSecretInvalidLength is the error returned when a hash secret is too short to be a bcrypt secret. ErrSecretInvalidLength = errors.New("github.com/go-crypt/x/bcrypt: secret has an invalid length for a bcrypt secret") )
Functions ¶
func Base64Decode ¶
Base64Decode is the base64 decoder for bcrypt.
func Base64Encode ¶
Base64Encode is the base64 encoder for bcrypt.
func CompareHashAndPassword ¶
CompareHashAndPassword compares a bcrypt hashed password with its possible plaintext equivalent. Returns nil on success, or an error on failure.
func Cost ¶
Cost returns the hashing cost used to create the given hashed password. When, in the future, the hashing cost of a password system needs to be increased in order to adjust for greater computational power, this function allows one to establish which passwords need to be updated.
func DecodeSecret ¶
DecodeSecret decodes a valid bcrypt secret into a salt and key. This function will panic if the secret does not have the len of EncodedSaltSize + EncodedHashSize.
func GenerateFromPassword ¶
GenerateFromPassword returns the bcrypt hash of the password at the given cost. If the cost given is less than MinCost, the cost will be set to DefaultCost, instead. Use CompareHashAndPassword, as defined in this package, to compare the returned hashed password with its cleartext version.
func GenerateFromPasswordSalt ¶
GenerateFromPasswordSalt returns the bcrypt hash of the password at the given cost. If the cost given is less than MinCost, the cost will be set to DefaultCost, instead. Use CompareHashAndPassword, as defined in this package, to compare the returned hashed password with its cleartext version.
Types ¶
type HashVersionTooNewError ¶
type HashVersionTooNewError byte
The error returned from CompareHashAndPassword when a hash was created with a bcrypt algorithm newer than this implementation.
func (HashVersionTooNewError) Error ¶
func (hv HashVersionTooNewError) Error() string
type InvalidCostError ¶
type InvalidCostError int
func (InvalidCostError) Error ¶
func (ic InvalidCostError) Error() string
type InvalidHashPrefixError ¶
type InvalidHashPrefixError byte
The error returned from CompareHashAndPassword when a hash starts with something other than '$'
func (InvalidHashPrefixError) Error ¶
func (ih InvalidHashPrefixError) Error() string
type InvalidSaltSizeError ¶
type InvalidSaltSizeError struct {
// contains filtered or unexported fields
}
func (InvalidSaltSizeError) Error ¶
func (iss InvalidSaltSizeError) Error() string