Skip to content

Instantly share code, notes, and snippets.

View ciehanski's full-sized avatar

Ryan Ciehanski ciehanski

View GitHub Profile
@ciehanski
ciehanski / argon2.go
Last active June 13, 2020 01:30
Using argon2 in Golang
func hashPassword(password string) (string, error) {
salt := make([]byte, argonSaltLen)
_, err := rand.Read(salt)
if err != nil {
return "", err
}
passwordHash := argon2.IDKey([]byte(password), salt, argonTime, argonMemory, argonThreads, argonKeyLen)
// Base64 encode the salt and hashed password
b64Salt := base64.RawStdEncoding.EncodeToString(salt)
b64Hash := base64.RawStdEncoding.EncodeToString(passwordHash)