Documentation
¶
Overview ¶
Package desext implements the DES Extended hashing algorithm for crypt(3).
Index ¶
- Constants
- func Check(hash, password string) error
- func Key(password, salt []byte, rounds uint32) ([]byte, error)
- func NewHash(password string, rounds uint32) (string, error)
- func Params(hash string) (salt []byte, rounds uint32, err error)
- type InvalidRoundsError
- type InvalidSaltError
- type InvalidSaltLengthError
- type UnsupportedPrefixError
Examples ¶
Constants ¶
const ( MinRounds = 1 MaxRounds = 1<<24 - 1 DefaultRounds = 5001 )
const Prefix = "_"
const SaltLength = 4
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check compares the given crypt(3) DES Extended 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/desext" ) func main() { hash := "_6C/.yaiu.qYIjNR7X.s" fmt.Println(desext.Check(hash, "password")) fmt.Println(desext.Check(hash, "test")) }
Output: <nil> hash and password mismatch
func Key ¶
Key returns a DES Extended key derived from the password, salt and rounds.
Example ¶
package main import ( "fmt" "github.com/sergeymakinen/go-crypt/desext" "github.com/sergeymakinen/go-crypt/hash" ) func main() { salt, rounds, _ := desext.Params("_6C/.yaiu.qYIjNR7X.s") fmt.Println(string(salt)) fmt.Println(rounds) key, _ := desext.Key([]byte("password"), salt, rounds) fmt.Println(hash.BigEndianEncoding.EncodeToString(key)) }
Output: yaiu 5000 .qYIjNR7X.s
func NewHash ¶
NewHash returns the crypt(3) DES Extended hash of the password with the given rounds.
func Params ¶
Params returns the hashing salt and rounds used to create the given crypt(3) DES Extended hash.
Example ¶
package main import ( "fmt" "github.com/sergeymakinen/go-crypt/desext" ) func main() { salt, rounds, _ := desext.Params("_6C/.yaiu.qYIjNR7X.s") fmt.Println(string(salt)) fmt.Println(rounds) }
Output: yaiu 5000
Types ¶
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