Skip to content

Instantly share code, notes, and snippets.

@yesmar
Created December 22, 2017 18:59
Show Gist options
  • Save yesmar/52fc99326b76603d913bc35b837871ad to your computer and use it in GitHub Desktop.
Save yesmar/52fc99326b76603d913bc35b837871ad to your computer and use it in GitHub Desktop.
Key derivation using Argon2
// https://godoc.org/golang.org/x/crypto/argon2
package main
import (
"crypto/rand"
"encoding/hex"
"fmt"
"golang.org/x/crypto/argon2"
)
func makeToken(length uint) []byte {
randomBytes := make([]byte, 32)
_, err := rand.Read(randomBytes)
if err != nil {
panic(err)
}
return randomBytes[:length]
}
func main() {
salt := makeToken(32)
key := argon2.Key([]byte("some password"), salt, 4, 32*1024, 4, 32)
fmt.Println("salt", hex.EncodeToString(salt), "\n", "key", hex.EncodeToString(key))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment