pbkdf2

package
v0.0.0-...-60b8695 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package pbkdf2 implements the PBKDF2 algorithm method used to hash passwords.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Algorithm

type Algorithm string

Algorithm is the type of the accepted algorithms.

const (
	// Sha256 is the sha256 algorithm.
	Sha256 Algorithm = "sha256"

	// Sha512 is the sha512 algorithm.
	Sha512 Algorithm = "sha512"
)

func ParseAlgorithm

func ParseAlgorithm(str string) (Algorithm, error)

ParseAlgorithm parses a string into an Algorithm and checks if it is supported.

func (*Algorithm) Hash

func (a *Algorithm) Hash() hash.Hash

Hash returns the hash.Hash that calculates the hash.

func (Algorithm) MarshalText

func (a Algorithm) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Algorithm) String

func (a Algorithm) String() string

Algorithm implements fmt.Stringer.

type PBKDF2

type PBKDF2 struct {
	// Iterations is the number of iterations to use in the PBKDF2 algorithm.
	Iterations int

	// Algorithm is the hashing algorithm used.
	Algorithm Algorithm

	// SaltLength is the length of the salt used.
	SaltLength int

	// KeyLength is the length of the desired key.
	KeyLength int
}

PBKDF2 is a password derivation method.

func Default

func Default() PBKDF2

Default returns a the default PBKDF2 instance.

func (PBKDF2) Hash

func (p PBKDF2) Hash(plain string) (string, error)

Hash hashes a plain text password.

func (PBKDF2) Name

func (PBKDF2) Name() string

Name returns the name of the PBKDF2 hashing method.

func (PBKDF2) Validate

func (PBKDF2) Validate(hashed, plain string) (bool, error)

Validate validates a plaintext password against a hashed one. The format of the hashed password should be:

PBKDF2$<algorithm>$<iterations>$<salt>$<key in base64>

Jump to

Keyboard shortcuts

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