使用带有 javascript 的 sha256 加密密码以保护安全攻击

Encrypt password to protect security attacks using sha256 with javascript

我想在 jsp 页面上使用 sha256 加密我的密码,使用 javascript 来保护各种安全攻击,并将此加密密码发送到 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 javascript 您需要使用库,快速 google search give this page http://www.movable-type.co.uk/scripts/sha256.html you can also take a look at this question Are there any SHA-256 javascript implementations that are generally considered trustworthy?