Skip to content

Instantly share code, notes, and snippets.

@9bany
Created July 25, 2022 01:37
Show Gist options
  • Save 9bany/9a0e817ee14ad37b8a494ff6b48c2986 to your computer and use it in GitHub Desktop.
Save 9bany/9a0e817ee14ad37b8a494ff6b48c2986 to your computer and use it in GitHub Desktop.
Hash password with salt
import (
"crypto/rand"
"fmt"
"io"
"log"
"code.google.com/p/go.crypto/scrypt"
)
const (
PW_SALT_BYTES = 32
PW_HASH_BYTES = 64
password = "hello"
)
func main() {
salt := make([]byte, PW_SALT_BYTES)
_, err := io.ReadFull(rand.Reader, salt)
if err != nil {
log.Fatal(err)
}
hash, err := scrypt.Key([]byte(password), salt, 1<<14, 8, 1, PW_HASH_BYTES)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%x\n", hash)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment