Documentation ¶
Overview ¶
Package md5crypt provides helpful abstractions for an implementation of crypt (MD5) and implements github.com/go-crypt/crypt interfaces.
This implementation is loaded by crypt.NewDecoderAll.
Index ¶
- Constants
- func Decode(encodedDigest string) (digest algorithm.Digest, err error)
- func DecodeVariant(v Variant) func(encodedDigest string) (digest algorithm.Digest, err error)
- func RegisterDecoder(r algorithm.DecoderRegister) (err error)
- func RegisterDecoderCommon(r algorithm.DecoderRegister) (err error)
- func RegisterDecoderSun(r algorithm.DecoderRegister) (err error)
- type Digest
- func (d *Digest) Encode() string
- func (d *Digest) Match(password string) (match bool)
- func (d *Digest) MatchAdvanced(password string) (match bool, err error)
- func (d *Digest) MatchBytes(passwordBytes []byte) (match bool)
- func (d *Digest) MatchBytesAdvanced(passwordBytes []byte) (match bool, err error)
- func (d *Digest) String() string
- type Hasher
- func (h *Hasher) Hash(password string) (digest algorithm.Digest, err error)
- func (h *Hasher) HashWithSalt(password string, salt []byte) (digest algorithm.Digest, err error)
- func (h *Hasher) MustHash(password string) (digest algorithm.Digest)
- func (h *Hasher) Validate() (err error)
- func (h *Hasher) WithOptions(opts ...Opt) (err error)
- type Opt
- type Variant
Constants ¶
const ( // EncodingFmt is the encoding format for this algorithm. EncodingFmt = "$1$%s$%s" // EncodingFmtSun is the encoding format for this algorithm when using md5crypt.VariantSun. EncodingFmtSun = "$md5$%s$$%s" // EncodingFmtSunIterations is the encoding format for this algorithm when using md5crypt.VariantSun and iterations more than 0. EncodingFmtSunIterations = "$md5,iterations=%d$%s$$%s" // AlgName is the name for this algorithm. AlgName = "md5crypt" // AlgIdentifier is the identifier used in this algorithm. AlgIdentifier = "1" // AlgIdentifierVariantSun is the identifier used in this algorithm when using md5crypt.VariantSun. AlgIdentifierVariantSun = "md5" // VariantNameStandard is the md5crypt.Variant name for md5crypt.VariantStandard. VariantNameStandard = "standard" // VariantNameSun is the md5crypt.Variant name for md5crypt.VariantSun. VariantNameSun = "sun" // SaltLengthMin is the minimum salt size accepted. SaltLengthMin = 1 // SaltLengthMax is the maximum salt size accepted. SaltLengthMax = 8 // SaltLengthDefault is the default salt size. SaltLengthDefault = SaltLengthMax // SaltCharSet are the valid characters for the salt. SaltCharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./" // IterationsMin is the minimum iterations accepted. IterationsMin = 0 // IterationsMax is the maximum iterations accepted. IterationsMax = math.MaxUint32 // IterationsDefault is the default iterations. IterationsDefault = 34000 )
Variables ¶
This section is empty.
Functions ¶
func DecodeVariant ¶
DecodeVariant the encoded digest into a algorithm.Digest provided it matches the provided Variant. If VariantNone is used all variants can be decoded.
func RegisterDecoder ¶
func RegisterDecoder(r algorithm.DecoderRegister) (err error)
RegisterDecoder the decoder with the algorithm.DecoderRegister.
func RegisterDecoderCommon ¶
func RegisterDecoderCommon(r algorithm.DecoderRegister) (err error)
RegisterDecoderCommon registers specifically the common decoder variant with the algorithm.DecoderRegister.
func RegisterDecoderSun ¶
func RegisterDecoderSun(r algorithm.DecoderRegister) (err error)
RegisterDecoderSun registers specifically the sun decoder variant with the algorithm.DecoderRegister.
Types ¶
type Digest ¶
type Digest struct {
// contains filtered or unexported fields
}
Digest is a algorithm.Digest which handles md5crypt hashes.
func (*Digest) Match ¶
Match returns true if the string password matches the current md5crypt.Digest.
func (*Digest) MatchAdvanced ¶
MatchAdvanced is the same as Match except if there is an error it returns that as well.
func (*Digest) MatchBytes ¶
MatchBytes returns true if the []byte passwordBytes matches the current md5crypt.Digest.
func (*Digest) MatchBytesAdvanced ¶
MatchBytesAdvanced is the same as MatchBytes except if there is an error it returns that as well.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher is a crypt.Hash for md5crypt which can be initialized via md5crypt.New using a functional options pattern.
func (*Hasher) Hash ¶
Hash performs the hashing operation and returns either a algorithm.Digest or an error.
func (*Hasher) HashWithSalt ¶
HashWithSalt overloads the Hash method allowing the user to provide a salt. It's recommended instead to configure the salt size and let this be a random value generated using crypto/rand.
func (*Hasher) MustHash ¶
MustHash overloads the Hash method and panics if the error is not nil. It's recommended if you use this option to utilize the Validate method first or handle the panic appropriately.
func (*Hasher) Validate ¶
Validate checks the settings/parameters for this md5crypt.Hasher and returns an error.
func (*Hasher) WithOptions ¶
WithOptions applies the provided functional options provided as a md5crypt.Opt to the md5crypt.Hasher.
type Opt ¶
Opt describes the functional option pattern for the md5crypt.Hasher.
func WithIterations ¶
WithIterations sets the iterations parameter of the resulting md5crypt.Digest. Only valid for the Sun variant. This is encoded in the hash with the 'iterations' parameter. Minimum is 0, Maximum is 4294967295. Default is 34000.
func WithRounds ¶
WithRounds is an alias for md5crypt.WithIterations.
func WithSaltLength ¶
WithSaltLength adjusts the salt size (in bytes) of the resulting md5crypt.Digest. Minimum is 1, Maximum is 8. Default is 8.
func WithVariant ¶
WithVariant is used to configure the md5crypt.Variant of the resulting md5crypt.Digest. Default is md5crypt.VariantStandard.
func WithVariantName ¶
WithVariantName uses the variant name or identifier to configure the md5crypt.Variant of the resulting md5crypt.Digest. Default is md5crypt.VariantStandard.