我正在开发java应用程序,我被要求使用以下信息生成安全代码。
Value to be encrypted ="test1234";
passPhrase = "testValue"
saltValue = "testValue"
hashAlgorithm = "SHA1"
passwordIterations = 2
initVector = "testValue"
keySize = 256
有人可以让我知道使用基于上述提及值的 SHA1 算法生成哈希值的方法是什么。
这个问题有点模糊,但我认为您可能想使用 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 有一个更深入的解释