SHA-256 encryption wrong result in Android

Posted by user642966 on Stack Overflow See other posts from Stack Overflow or by user642966
Published on 2012-11-30T20:38:12Z Indexed on 2012/12/01 23:04 UTC
Read the original article Hit count: 269

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about android

Related posts about salt