我正在开发java应用程序,并且我被要求使用以下信息生成安全代码。
Value to be encrypted ="test1234";
passPhrase = "testValue"
saltValue = "testValue"
hashAlgorithm = "SHA1"
passwordIterations = 2
initVector = "testValue"
keySize = 256
有人可以根据上面提到的值,让我知道使用SHA1算法生成哈希值的方法是什么。
答案 0 :(得分:1)
这个问题有点模糊,但我想你可能想用PBKDF2来生成哈希。幸运的是,它在Java SE 6 +中非常简单
KeySpec spec = new PBEKeySpec(passsword.toCharArray(), salt,
iterations, derivedKeyLength);
SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
return f.generateSecret(spec).getEncoded();
http://jerryorr.blogspot.com/2012/05/secure-password-storage-lots-of-donts.html
有更深入的解释