Skip to content

Instantly share code, notes, and snippets.

@yifan-gu
Created August 31, 2015 23:53
Show Gist options
  • Save yifan-gu/622a7057a652a568476f to your computer and use it in GitHub Desktop.
Save yifan-gu/622a7057a652a568476f to your computer and use it in GitHub Desktop.
bcrypt
package main
import (
"fmt"
"golang.org/x/crypto/bcrypt"
)
func main() {
token, err := bcrypt.GenerateFromPassword([]byte("Cac3j5M0hvRRagKoVhk_v8DSMWit6gkyGQZ_5rMSMPxiJ_-QjWxPHT_YDXol7eNyiWusdhBn2weQLqlD2h84HA=="), bcrypt.DefaultCost)
if err != nil {
panic(err)
}
fmt.Println("token:", string(token))
fmt.Println("compare result:", bcrypt.CompareHashAndPassword(token, []byte("Cac3j5M0hvRRagKoVhk_v8DSMWit6gkyGQZ_5rMSMPxiJ_-QjWxPHT_YDXol7eNyiWusdhBn2weQLqlD2h84HA==randombits!!!!!!!!!!")))
}
@yifan-gu
Copy link
Author

go run testbcrypt.go

token: $2a$10$egY6/ESH1c9l0ZP4c1x8qODiWiZ8fNfdJ6upYmGt0cnvbl32QzlYC
compare result: <nil>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment