【问题标题】:newbie question : Apache Shiro recover password新手问题:Apache Shiro 恢复密码
【发布时间】:2021-12-18 11:30:13
【问题描述】:

我对加密/解密没什么经验..

对于我的网络应用程序,我想使用 Apache Shiro 登录用户,使用加盐密码..

这是我阅读的文章:http://shiro.apache.org/realm.html#Realm-HashingCredentials 和生成加盐密码的代码:

import org.apache.shiro.crypto.hash.Sha256Hash;
import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
...

//We'll use a Random Number Generator to generate salts.  This 
//is much more secure than using a username as a salt or not 
//having a salt at all.  Shiro makes this easy. 
//
//Note that a normal app would reference an attribute rather 
//than create a new RNG every time: 
RandomNumberGenerator rng = new SecureRandomNumberGenerator();
Object salt = rng.nextBytes();

//Now hash the plain-text password with the random salt and multiple 
//iterations and then Base64-encode the value (requires less space than Hex): 
String hashedPasswordBase64 = new Sha256Hash(plainTextPassword, salt, 1024).toBase64();

User user = new User(username, hashedPasswordBase64);
//save the salt with the new account.  The HashedCredentialsMatcher 
//will need it later when handling login attempts: 
user.setPasswordSalt(salt);
userDAO.create(user);

这给了我一个加密的密码.. 但是我怎样才能恢复纯文本密码呢?有可能吗?

【问题讨论】:

    标签: java passwords shiro salt


    【解决方案1】:

    感谢本杰明·马威尔

    这只有在理论上和/或有很多钱的情况下才有可能。 您可以使用在 GPU 上运行的黑客工具,但即便如此 可能需要数年才能找到它。 这正是重点:基于密码的密钥派生函数 旨在创建一个不可恢复的哈希。

    Shiro 2.0 将使用更好的 KDF,例如 Argon2 或 bcrypt/script, 这需要大量的内存和 cpu 才能使攻击不 可行。

    如果您有权访问存储密码的数据库,我 只需设置一个新密码并忘记旧密码,如果 可能。

    【讨论】:

    • 不客气。 ?
    猜你喜欢
    • 2015-01-05
    • 2015-10-24
    • 2020-12-11
    • 2023-04-07
    • 2014-08-06
    • 2014-09-18
    • 2016-04-02
    • 2014-12-06
    • 2011-11-27
    相关资源
    最近更新 更多