package service import ( "fmt" "golang.org/x/crypto/bcrypt" ) // bcrypt加密 func encode() { password, err := bcrypt.GenerateFromPassword([]byte("123"), 10) if err != nil { panic(err) } fmt.Println(string(password)) err = bcrypt.CompareHashAndPassword(password, []byte("123")) if err != nil { panic(err) } fmt.Println("correct") }