Created
October 20, 2019 19:02
-
-
Save kovacshuni/be9684ed568bfbefe33d0dd9732a20f1 to your computer and use it in GitHub Desktop.
generate-password-hash-scrypt
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
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