我调用以下命令并创建密码哈希。
ByteString password = ByteString.copyFrom(DigestUtils.sha256("mypassword"));
但现在我需要从客户端(JavaScript)发送 sha256 转换后的密码消息。我厌倦了使用 CryptoJS,如下所示
var pass = CryptoJS.SHA256(document.getElementById('password').value);
var passhash = pass.toString(CryptoJS.enc.Latin1)
login(passhash);
我尝试了所有 Base64、Latin1 和 Hex 类型来获取字符串。但它不会产生与 Java 中相同的密码
最佳答案
问题出在字符编码上。以下解决了问题。
在 JS 中:
var password = pass.toString(CryptoJS.enc.Utf16);
在 Java 中:
byte[] passhash = jsCryptoString.getBytes("UTF-16BE");
关于javascript - JavaScript 中的 DigestUtils sha256 编码等效项是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14435132/