Created
December 22, 2017 18:59
-
-
Save yesmar/52fc99326b76603d913bc35b837871ad to your computer and use it in GitHub Desktop.
Key derivation using Argon2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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