Created
July 25, 2022 01:37
-
-
Save 9bany/9a0e817ee14ad37b8a494ff6b48c2986 to your computer and use it in GitHub Desktop.
Hash password with salt
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
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