尽管我还没有找到与PHP的crypt函数完全相同的“ Go crypt函数”,但我找到了另一种方法。
以下解决了我的问题
import "golang.org/x/crypto/bcrypt"// check will be nil if the bcrypt version of "enter-new-password" is the same as the "$2a$09$f5561d2634fb28a969f2dO8QeQ70f4bjCnF/.GvPpjj.8jgmtzZP2" . Otherwise check will be an error objectcheck := bcrypt.CompareHashAndPassword([]byte("$2a$09$f5561d2634fb28a969f2dO8QeQ70f4bjCnF/.GvPpjj.8jgmtzZP2"),[]byte("enter-new-password"))log.Println(check)在
golang.org/x/crypto/bcrypt/bcrypt_test.go对如何使用这个模块一些有用的例子。
显然,PHP的crypt函数具有多种不同的散列值方式,例如sha256,sha512,blowfish等。似乎那里有很多go
lang模块,但是您必须明确说明散列类型,成本等。在我的问题中,
$2a$作为哈希值前缀的存在表明使用了一些河豚类型的哈希。我以前的一些尝试没有考虑到这一点。实际上,尝试3中的模块不支持河豚。



