Apache Shiro的Sha256Hash是基于像PBKDF2WithHmacSHA256这样的通用规范吗?
下面的例子证明了,Shiros Sha256Hash不会创建有效的PBKDF2WithHmacSHA256散列。
public static byte[] getEncryptedPassword(
String password,
byte[] salt,
int iterations,
int derivedKeyLength
) throws NoSuchAlgorithmException, InvalidKeySpecException {
KeySpec keySpec = new PBEKeySpec(
password.toCharArray(),
salt,
iterations,
derivedKeyLength * 8
);
SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
return f.generateSecret(keySpec).getEncoded();
}
@Test
public void testHashing(){
byte[] salt = new SecureRandomNumberGenerator().nextBytes().getBytes();
byte[] hash1 = new Sha256Hash("1234", salt, 1024).getBytes();
byte[] hash2 = getEncryptedPassword("1234", salt, 1024, 32);
assertTrue(hash1.equals(hash2));
}有没有一种通用的方法来使用shiro的PBKDF2WithHmacSHA256,或者我必须实现我自己的CredentialMatcher?
发布于 2016-02-08 14:14:18
根据Shiro user list on nabble no,Shiro不提供PBKDF2 (或BCrypt或SCrypt)。
请注意,将Java 8 does have PBKDF2-HMAC-SHA-512 available now作为PBKDF2WithHmacSHA512 -请改用它。SHA-512尤其具有64位操作,这降低了基于GPU的攻击者的优势。除了1024之外,还要使用更多的迭代-看看您的系统在负载下可以轻松地处理什么!
https://stackoverflow.com/questions/32401239
复制相似问题