这是一个桌面应用程序,所以只有我想要基本的登录安全性,我虽然使用一个函数来加密密码,另一个我从UI传递密码并将散列保存到db并返回true o false取决于是否匹配或不
我尝试使用官方jasypt网站上的池化版本,我可以加密,但我不知道如何解密它。
//Function to encrypt password
public static String cifrarClave(String clave) {
PooledStringDigester digester = new PooledStringDigester();
digester.setPoolSize(4);
digester.setAlgorithm("SHA-1");
digester.setIterations(50000);
digester.setSaltSizeBytes(32);
//String return is hash that I save into db
return digester.digest(clave);
}
//Function to decrypt password
//clave is old plain that user enter from UI and I want to compare from hash save it into db
public static boolean validarClave(String clave, String hash) {
PooledStringDigester digester = new PooledStringDigester();
digester.setPoolSize(4);
digester.setAlgorithm("SHA-1");
digester.setIterations(50000);
String digest = digester.digest(clave);
//Always fails at that point, I get different hash from compare clave
return digester.matches(digest, hash);
}
我是安全新手,所以我对安全性知之甚少,我接受其他建议或替代方案,我只想要一个有效的例子。
答案 0 :(得分:1)
当您使用两个哈希摘要而不是明文消息和先前计算的摘要调用它时,您正在使用jasypt的matches(message, digest)
函数。
在validarClave()
中,您首先会从用户的明文密码(clave
)中不必要地计算摘要,然后将其传递给匹配器:
String digest = digester.digest(clave);
//Always fails at that point, I get different hash from compare clave
return digester.matches(digest, hash);
如果您只是将明文密码传递给匹配器,您的方法将正常工作,如下所示:
digester.matches(clave, hash);
更多信息可在jasypt的javadocs和code examples找到。