pbkdf2

package module
v0.0.0-...-574296f Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2012 License: MIT Imports: 2 Imported by: 4 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Package pbkdf2

Package pbkdf2 implements PBKDF2 key derivation function.

(Slightly modified version of https://bitbucket.org/taruti/pbkdf2.go, with password helper functions removed)

Functions

func WithHMAC
func WithHMAC(hash func() hash.Hash, password []byte, salt []byte, iterations int, outlen int) []byte

WithHMAC derives key of length outlen from the provided password, salt, and the number of iterations using PKCS#5 PBKDF2 with the provided hash function in HMAC.

Caller is responsible to make sure that outlen < (2^32-1) * hash.Size().

Example

package main

import (
	"fmt"
	"crypto/rand"
	"crypto/sha256"
	"github.com/dchest/pbkdf2"
)


func main() {
	password := "hello"
	// Get random salt
	salt := make([]byte, 32)
	if _, err := rand.Reader.Read(salt); err != nil {
		panic("random reader failed")
	}
	// Derive key
	key := pbkdf2.WithHMAC(sha256.New, password, salt, 9999, 64)
	fmt.Printf("%x", key)
}

Documentation

Overview

Package pbkdf2 implements PBKDF2 key derivation function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithHMAC

func WithHMAC(hash func() hash.Hash, password []byte, salt []byte, iterations int, outlen int) []byte

WithHMAC derives key of length outlen from the provided password, salt, and the number of iterations using PKCS#5 PBKDF2 with the provided hash function in HMAC.

Caller is responsible to make sure that outlen < (2^32-1) * hash.Size().

Types

This section is empty.

Jump to

Keyboard shortcuts

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