Documentation ¶
Overview ¶
Package sunmd5 implements the Sun MD5 hashing algorithm for crypt(3).
Index ¶
- Constants
- func Check(hash, password string) error
- func Key(password, salt []byte, rounds uint32, opts *CompatibilityOptions) ([]byte, error)
- func NewHash(password string, rounds uint32) (string, error)
- type CompatibilityOptions
- type InvalidPasswordLengthError
- type InvalidRoundsError
- type InvalidSaltError
- type InvalidSaltLengthError
- type UnsupportedPrefixError
Examples ¶
Constants ¶
const ( MaxSaltLength = 8 DefaultSaltLength = MaxSaltLength )
const ( BasicRounds = 4096 MaxRounds = 1<<32 - 1 - BasicRounds DefaultRounds = 0 )
const ( PrefixNonZeroRounds = "$md5," // normally used when the hash uses a non-zero round count PrefixZeroRounds = "$md5$" // normally used when the hash uses a zero round count )
const MaxPasswordLength = 255
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check compares the given crypt(3) Sun MD5 hash with a new hash derived from the password. Returns nil on success, or an error on failure.
Example ¶
package main import ( "fmt" "github.com/sergeymakinen/go-crypt/sunmd5" ) func main() { hash := "$md5,rounds=5000$ReCRHeOH$$WOV3YlBRWykkmQDJc.uia/" fmt.Println(sunmd5.Check(hash, "password")) fmt.Println(sunmd5.Check(hash, "test")) }
Output: <nil> hash and password mismatch
func Key ¶
func Key(password, salt []byte, rounds uint32, opts *CompatibilityOptions) ([]byte, error)
Key returns a Sun MD5 key derived from the password, salt, rounds and compatibility options.
The opts parameter is optional. If nil, default options are used.
Example ¶
package main import ( "fmt" "github.com/sergeymakinen/go-crypt/hash" "github.com/sergeymakinen/go-crypt/sunmd5" ) func main() { salt, rounds, opts, _ := sunmd5.Params("$md5,rounds=5000$ReCRHeOH$$WOV3YlBRWykkmQDJc.uia/") fmt.Println(string(salt)) fmt.Println(rounds) key, _ := sunmd5.Key([]byte("password"), salt, rounds, opts) fmt.Println(hash.LittleEndianEncoding.EncodeToString(key)) }
Output: ReCRHeOH 5000 WOV3YlBRWykkmQDJc.uia/
Types ¶
type CompatibilityOptions ¶
CompatibilityOptions are the key derivation parameters required to produce keys from old/non-standard hashes.
func Params ¶
func Params(hash string) (salt []byte, rounds uint32, opts *CompatibilityOptions, err error)
Params returns the hashing salt, rounds and compatibility options used to create the given crypt(3) Sun MD5 hash.
Example ¶
package main import ( "fmt" "github.com/sergeymakinen/go-crypt/sunmd5" ) func main() { salt, rounds, _, _ := sunmd5.Params("$md5,rounds=5000$ReCRHeOH$$WOV3YlBRWykkmQDJc.uia/") fmt.Println(string(salt)) fmt.Println(rounds) }
Output: ReCRHeOH 5000
type InvalidPasswordLengthError ¶
type InvalidPasswordLengthError int
InvalidPasswordLengthError values describe errors resulting from an invalid length of a password.
func (InvalidPasswordLengthError) Error ¶
func (e InvalidPasswordLengthError) Error() string
type InvalidRoundsError ¶
type InvalidRoundsError uint32
InvalidRoundsError values describe errors resulting from an invalid round count.
func (InvalidRoundsError) Error ¶
func (e InvalidRoundsError) Error() string
type InvalidSaltError ¶
type InvalidSaltError byte
InvalidSaltError values describe errors resulting from an invalid character in a hash string.
func (InvalidSaltError) Error ¶
func (e InvalidSaltError) Error() string
type InvalidSaltLengthError ¶
type InvalidSaltLengthError int
InvalidSaltLengthError values describe errors resulting from an invalid length of a salt.
func (InvalidSaltLengthError) Error ¶
func (e InvalidSaltLengthError) Error() string
type UnsupportedPrefixError ¶
type UnsupportedPrefixError string
UnsupportedPrefixError values describe errors resulting from an unsupported prefix string.
func (UnsupportedPrefixError) Error ¶
func (e UnsupportedPrefixError) Error() string