Documentation ¶
Overview ¶
Package nthash implements the NT Hash hashing algorithm for crypt(3).
Index ¶
Examples ¶
Constants ¶
View Source
const MaxPasswordLength = 256
View Source
const Prefix = "$3$"
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check compares the given crypt(3) NT Hash 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/nthash" ) func main() { hash := "$3$$8846f7eaee8fb117ad06bdd830b7586c" fmt.Println(nthash.Check(hash, "password")) fmt.Println(nthash.Check(hash, "test")) }
Output: <nil> hash and password mismatch
func Key ¶
Key returns a NT Hash key derived from the password and salt.
Example ¶
package main import ( "encoding/binary" "encoding/hex" "fmt" "unicode/utf16" "github.com/sergeymakinen/go-crypt/nthash" ) func main() { // UTF-8 to UTF-16 LE a := utf16.Encode([]rune("password")) b := make([]byte, len(a)*2) for i, r := range a { binary.LittleEndian.PutUint16(b[i*2:], r) } key, _ := nthash.Key(b) fmt.Println(hex.EncodeToString(key)) }
Output: 8846f7eaee8fb117ad06bdd830b7586c
Types ¶
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 UnsupportedPrefixError ¶
type UnsupportedPrefixError string
UnsupportedPrefixError values describe errors resulting from an unsupported prefix string.
func (UnsupportedPrefixError) Error ¶
func (e UnsupportedPrefixError) Error() string
Click to show internal directories.
Click to hide internal directories.