0

The hash values of the same string is different in Javascript and Android for SHA-256:

Javascript Code:

var hashedPassword = CryptoJS.SHA256(userPassword);
var passwordText = hashedPassword.toString(CryptoJS.enc.Base64);

Android Code:

MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
byte[] hashedPassword = messageDigest.digest(userPassword.getBytes());
String hashedPasswordText = Base64.encodeToString(hashedPassword, Base64.DEFAULT).trim();

Output for String "beast":

In Javascript :

1bf417bd87162d5d77a5ce3259e81bdee9f8a0ef56bc0f12eadcd5805a94b708

In Android :

G/QXvYcWLV13pc4yWegb3un4oO9WvA8S6tzVgFqUtwg=
1
  • 1
    Your Javascript output string looks like Base16, not Base64. In fact, they're identical after transformation. Commented Mar 15, 2017 at 18:55

1 Answer 1

0

According to this answer CryptoJS.enc.Base64 requires another component. And if it does not find it it defaults to HEX.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.