【问题标题】:Encrypt password to protect security attacks using sha256 with javascript使用 sha256 和 javascript 加密密码以保护安全攻击
【发布时间】:2016-06-23 23:48:02
【问题描述】:

我想使用javascript在jsp页面本身上使用sha256加密我的密码以保护各种安全攻击并将这个加密的密码发送到spring控制器。但我无法生成散列字符串。 这是我的 JavaScript 代码。第一个警报来了,但不是第二个。我是否需要包含任何 jar 或 js 才能使 sha256 工作?

document.getElementById('loginButton').onclick = function() {
        var txt_string = document.getElementById('loginPassword').value; // gets data from input text
        alert('normal  password is' + txt_string);
        // encrypts data and adds it in #strcrypt element
        var hashedpassword = SHA256(txt_string);
        alert('hashed password is' + hashedpassword);
        return false;
    }

【问题讨论】:

  • 控制台是否出现错误? SHA256 是在哪里定义的?
  • 不要在 Web 客户端上散列密码,这既不安全也不是最佳实践,而是在服务器上散列它们。使用随机盐在 HMAC 上迭代大约 100 毫秒(盐需要与哈希一起保存)。使用 password_hash、PBKDF2、Bcrypt 等函数和类似函数。关键是让攻击者花费大量时间通过蛮力寻找密码。请参阅 OWASP(开放式 Web 应用程序安全项目)Password Storage Cheat Sheet
  • SHA-256 或任何哈希方法都不是加密。

标签: javascript jsp sha256


【解决方案1】:

javascript默认不包含SHA256你需要使用库,快google search给这个页面http://www.movable-type.co.uk/scripts/sha256.html你也可以看看这个问题Are there any SHA-256 javascript implementations that are generally considered trustworthy?

【讨论】:

    猜你喜欢
    • 2010-11-09
    • 2011-09-20
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-17
    相关资源
    最近更新 更多