SHA-256 encryption wrong result in Android
- by user642966
I am trying to encrypt 12345 using 1111 as salt using SHA-256 encoding and the answer I get is: 010def5ed854d162aa19309479f3ca44dc7563232ff072d1c87bd85943d0e930
which is not same as the value returned by this site:
http://hash.online-convert.com/sha256-generator
Here's the code snippet:
public String getHashValue(String entity, String salt){
byte[] hashValue = null;
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.update(entity.getBytes("UTF-8"));
digest.update(salt.getBytes("UTF-8"));
hashValue = digest.digest();
} catch (NoSuchAlgorithmException e) {
Log.i(TAG, "Exception "+e.getMessage());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return BasicUtil.byteArrayToHexString(hashValue);
}
I have verified my printing method with a sample from SO and result is fine. Can someone tell me what's wrong here?
And just to clarify - when I encrypt same value & salt in iOS code, the returned value is same as the value given by the converting site.