...

Package pbkdf2

import "github.com/xdg-go/pbkdf2"
Overview
Index

Overview ▾

Package pbkdf2 implements password-based key derivation using the PBKDF2 algorithm described in RFC 2898 and RFC 8018.

It provides a drop-in replacement for `golang.org/x/crypto/pbkdf2`, with the following benefits:

- Released as a module with semantic versioning

- Does not pull in dependencies for unrelated `x/crypto/*` packages

- Supports Go 1.9+

See https://tools.ietf.org/html/rfc8018#section-4 for security considerations in the selection of a salt and iteration count.

func Key

func Key(password, salt []byte, iterCount, keyLen int, h func() hash.Hash) []byte

Key generates a derived key from a password using the PBKDF2 algorithm. The inputs include salt bytes, the iteration count, desired key length, and a constructor for a hashing function. For example, for a 32-byte key using SHA-256:

key := Key([]byte("trustNo1"), salt, 10000, 32, sha256.New)