pbkdf2

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2019 License: BSD-3-Clause Imports: 2 Imported by: 171

Documentation

Overview

Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.

A key derivation function is useful when encrypting data based on a password or any other not-fully-random data. It uses a pseudorandom function to derive a secure encryption key based on the password.

While v2.0 of the standard defines only one pseudorandom function to use, HMAC-SHA1, the drafted v2.1 specification allows use of all five FIPS Approved Hash Functions SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512 for HMAC. To choose, you can pass the `New` functions from the different SHA packages to pbkdf2.Key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

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

Key derives a key from the password, salt and iteration count, returning a []byte of length keylen that can be used as cryptographic key. The key is derived based on the method described as PBKDF2 with the HMAC variant using the supplied hash function.

For example, to use a HMAC-SHA-1 based PBKDF2 key derivation function, you can get a derived key for e.g. AES-256 (which needs a 32-byte key) by doing:

dk := pbkdf2.Key([]byte("some password"), salt, 4096, 32, sha1.New)

Remember to get a good random salt. At least 8 bytes is recommended by the RFC.

Using a higher iteration count will increase the cost of an exhaustive search but will also make derivation proportionally slower.

func Key64

func Key64(password, salt []byte, iter, keyLen int64, h func() hash.Hash) []byte

Key64 derives a key from the password, salt and iteration count, returning a []byte of length keylen that can be used as cryptographic key. Key64 uses int64 for the iteration count and key length to allow larger values. The key is derived based on the method described as PBKDF2 with the HMAC variant using the supplied hash function.

For example, to use a HMAC-SHA-1 based PBKDF2 key derivation function, you can get a derived key for e.g. AES-256 (which needs a 32-byte key) by doing:

dk := pbkdf2.Key([]byte("some password"), salt, 4096, 32, sha1.New)

Remember to get a good random salt. At least 8 bytes is recommended by the RFC.

Using a higher iteration count will increase the cost of an exhaustive search but will also make derivation proportionally slower.

Types

This section is empty.

Jump to

Keyboard shortcuts

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