Last active
August 24, 2023 01:34
-
-
Save acheong08/69ef87626652b27d4f73e37831c42b49 to your computer and use it in GitHub Desktop.
Translation of makeKeyHash.js to Go: https://gist.github.com/acheong08/d43897ed7c969de8e51b204528687e13
This file contains hidden or 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 ( | |
"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