Skip to content

Instantly share code, notes, and snippets.

@acheong08
Last active August 24, 2023 01:34
Show Gist options
  • Save acheong08/69ef87626652b27d4f73e37831c42b49 to your computer and use it in GitHub Desktop.
Save acheong08/69ef87626652b27d4f73e37831c42b49 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"golang.org/x/crypto/scrypt"
)
const (
cost = 32768
r = 8
p = 1
)
func getKey(e, t string) ([]byte, error) {
normalizedE := []byte(e)
normalizedT := []byte(t)
key, err := scrypt.Key(normalizedE, normalizedT, cost, r, p, 32)
if err != nil {
return nil, err
}
return key, nil
}
func MakeKeyHash(e, t string) (string, error) {
n, err := getKey(e, t)
if err != nil {
return "", err
}
hash := sha256.Sum256(n)
return hex.EncodeToString(hash[:]), nil
}
func main() {
hash, err := MakeKeyHash("ZsSjgKx4yaeBNCFipS)T", "jePEuEPhNsr8zguY3%98")
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println(hash)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment