Skip to content

Instantly share code, notes, and snippets.

@deluan
Created September 9, 2016 12:33
Show Gist options
  • Save deluan/f8b3d31f9b6ebf00424adf91344da1e0 to your computer and use it in GitHub Desktop.
Save deluan/f8b3d31f9b6ebf00424adf91344da1e0 to your computer and use it in GitHub Desktop.
Testing bcrypt in GoLang
///usr/bin/env go run "$0" "$@"; exit;
package main
import (
"fmt"
"os"
"golang.org/x/crypto/bcrypt"
)
func main() {
if len(os.Args) == 1 {
println("Usage: crypto.go <word to be encrypted>")
os.Exit(1)
}
p := []byte(os.Args[1])
h, err := bcrypt.GenerateFromPassword(p, 0)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(h))
if err := bcrypt.CompareHashAndPassword(h, p); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment