md5

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: 6 Imported by: 0

Documentation

Overview

Package md5 implements the MD5 hashing algorithm for crypt(3).

Index

Examples

Constants

View Source
const (
	MaxSaltLength     = 8
	DefaultSaltLength = MaxSaltLength
)
View Source
const Prefix = "$1$"

Variables

This section is empty.

Functions

func Check

func Check(hash, password string) error

Check compares the given crypt(3) 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/md5"
)

func main() {
	hash := "$1$ip0xp41O$7DHwMihQRmDjn2tiJ17mw."
	fmt.Println(md5.Check(hash, "password"))
	fmt.Println(md5.Check(hash, "test"))
}
Output:

<nil>
hash and password mismatch

func Key

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

Key returns a MD5 key derived from the password and salt.

Example
package main

import (
	"fmt"

	"github.com/sergeymakinen/go-crypt/hash"
	"github.com/sergeymakinen/go-crypt/md5"
)

func main() {
	salt, _ := md5.Salt("$1$ip0xp41O$7DHwMihQRmDjn2tiJ17mw.")
	fmt.Println(string(salt))

	key, _ := md5.Key([]byte("password"), salt)
	fmt.Println(hash.LittleEndianEncoding.EncodeToString(key))
}
Output:

ip0xp41O
7DHwMihQRmDjn2tiJ17mw.

func NewHash

func NewHash(password string) string

NewHash returns the crypt(3) MD5 hash of the password.

func Salt

func Salt(hash string) (salt []byte, err error)

Salt returns the hashing salt used to create the given crypt(3) MD5 hash.

Example
package main

import (
	"fmt"

	"github.com/sergeymakinen/go-crypt/md5"
)

func main() {
	salt, _ := md5.Salt("$1$ip0xp41O$7DHwMihQRmDjn2tiJ17mw.")
	fmt.Println(string(salt))
}
Output:

ip0xp41O

Types

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

Directories

Path Synopsis
Package md5crypt provides low-level access to MD5 crypt functions.
Package md5crypt provides low-level access to MD5 crypt functions.

Jump to

Keyboard shortcuts

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