des

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

Documentation

Overview

Package des implements the DES hashing algorithm for crypt(3).

Index

Examples

Constants

View Source
const MaxPasswordLength = 8
View Source
const Prefix = ""
View Source
const SaltLength = 2

Variables

This section is empty.

Functions

func Check

func Check(hash, password string) error

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

func main() {
	hash := "eNBO0nZMf3rWM"
	fmt.Println(des.Check(hash, "password"))
	fmt.Println(des.Check(hash, "test"))
}
Output:

<nil>
hash and password mismatch

func Key

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

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

Example
package main

import (
	"fmt"

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

func main() {
	salt, _ := des.Salt("eNBO0nZMf3rWM")
	fmt.Println(string(salt))

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

eN
BO0nZMf3rWM

func NewHash

func NewHash(password string) string

NewHash returns the crypt(3) DES 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) DES hash.

Example
package main

import (
	"fmt"

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

func main() {
	salt, _ := des.Salt("eNBO0nZMf3rWM")
	fmt.Println(string(salt))
}
Output:

eN

Types

type InvalidPasswordLengthError

type InvalidPasswordLengthError int

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

func (InvalidPasswordLengthError) Error

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 descrypt provides low-level access to DES crypt functions.
Package descrypt provides low-level access to DES crypt functions.

Jump to

Keyboard shortcuts

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