dinesh707
dinesh707

Reputation: 12582

What is DigestUtils sha256 encoding equivalent from JavaScript?

I call following and create the password hash.

ByteString password = ByteString.copyFrom(DigestUtils.sha256("mypassword"));

But now I need to send the sha256 converted password message from client (JavaScript). I tired to use CryptoJS as following

 var pass = CryptoJS.SHA256(document.getElementById('password').value);
    var passhash = pass.toString(CryptoJS.enc.Latin1)
    login(passhash);

I tried all Base64, Latin1, and Hex types to get the string. But it will not produce the same password as the one in Java

Upvotes: 1

Views: 1779

Answers (1)

dinesh707
dinesh707

Reputation: 12582

Problem was with character encoding. Following fixed the problem.

in JS:

var password = pass.toString(CryptoJS.enc.Utf16); 

In Java:

byte[] passhash = jsCryptoString.getBytes("UTF-16BE");

Upvotes: 1

Related Questions