1

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

2
  • Use bcrypt Commented Jan 21, 2013 at 8:50
  • But sha is fixed. Its used in server side authentication. May be next time :) Commented Jan 21, 2013 at 8:52

1 Answer 1

1

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"); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.