nthash

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

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

func Check(hash, password string) error

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

func Key(password []byte) ([]byte, error)

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

func NewHash

func NewHash(password string) (string, error)

NewHash returns the crypt(3) NT Hash hash of the password.

Types

type InvalidPasswordLengthError

type InvalidPasswordLengthError int

InvalidPasswordLengthError values describe errors resulting from an invalid length of a password.

func (InvalidPasswordLengthError) Error

type UnsupportedPrefixError

type UnsupportedPrefixError string

UnsupportedPrefixError values describe errors resulting from an unsupported prefix string.

func (UnsupportedPrefixError) Error

func (e UnsupportedPrefixError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL