Skip to content

Instantly share code, notes, and snippets.

@kovacshuni
Created October 20, 2019 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kovacshuni/be9684ed568bfbefe33d0dd9732a20f1 to your computer and use it in GitHub Desktop.
Save kovacshuni/be9684ed568bfbefe33d0dd9732a20f1 to your computer and use it in GitHub Desktop.
generate-password-hash-scrypt
package main
import (
"fmt"
"math/rand"
"os"
"time"
"golang.org/x/crypto/scrypt"
)
func main() {
random := rand.New(rand.NewSource(time.Now().UnixNano()))
salt1 := make([]byte, 0)
for i := 0; i < 16; i++ {
salt1 = append(salt1, byte(random.Intn(256)))
}
h, err := scrypt.Key([]byte(os.Args[1]), salt1, 32768, 8, 1, 32)
if err != nil {
panic(err)
}
fmt.Printf("passowrd=%s\n", os.Args[1])
fmt.Printf("salt=")
printByteArr(salt1)
fmt.Print("passwordHashed=")
printByteArr(h)
}
func printByteArr(a []byte) {
fmt.Print("[]byte{")
for i, b := range a {
if i == len(a)-1 {
fmt.Print(fmt.Sprintf("%d", b))
} else {
fmt.Print(fmt.Sprintf("%d, ", b))
}
}
fmt.Println("}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment