首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shiros Sha256Hash及其替代算法

Shiros Sha256Hash及其替代算法
EN

Stack Overflow用户
提问于 2015-09-04 23:05:29
回答 1查看 329关注 0票数 2

Apache Shiro的Sha256Hash是基于像PBKDF2WithHmacSHA256这样的通用规范吗?

下面的例子证明了,Shiros Sha256Hash不会创建有效的PBKDF2WithHmacSHA256散列。

代码语言:javascript
复制
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?

EN

回答 1

Stack Overflow用户

发布于 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之外,还要使用更多的迭代-看看您的系统在负载下可以轻松地处理什么!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32401239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档