Created
September 9, 2016 12:33
-
-
Save deluan/f8b3d31f9b6ebf00424adf91344da1e0 to your computer and use it in GitHub Desktop.
Testing bcrypt in GoLang
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
///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