我正在为我的应用程序加密密码,因为密码将存储在共享首选项中
我找到了bcrypt,读到了很多关于它的好东西,但我不能让它工作。
我使用的是jBCrypt。我按照说明做了这个测试。
String hashed = BCrypt.hashpw("dog", BCrypt.gensalt(12));
String candidate = BCrypt.hashpw("dog", BCrypt.gensalt(12));
if (BCrypt.checkpw(candidate, hashed)){
Toast.makeText(Loader.this, "equals", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(Loader.this, "don't match?", Toast.LENGTH_LONG).show();
}但是,每次我运行应用程序时,显示的toast是不匹配的吗?所以,当我在我的共享首选项中登录哈希密码,然后将其与用户输入进行比较时,它会说每次都是错误的,因为很明显,它每次都会给我一个不同的哈希。
发布于 2011-09-30 00:30:14
根据documentation的说法,BCrypt.checkpw()将明文密码作为其第一个参数。所以它应该是:
String hashed = BCrypt.hashpw("dog", BCrypt.gensalt(12));
String candidate = "dog";
if (BCrypt.checkpw(candidate, hashed)) {
Toast.makeText(Loader.this, "equals", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(Loader.this, "doesn't match?", Toast.LENGTH_LONG).show();
}https://stackoverflow.com/questions/7600395
复制相似问题