reset password
Author Message
jpascua
Posts: 197
Posted 02:51 May 06, 2015 |

Can someone explain what is meant by "SHA256 hash of the User’s email address. Note, this value should be the hex value represented as a 64- character string."?

Thanks.

neilchoksi
Posts: 29
Posted 03:01 May 06, 2015 |
Sha 256 is an encryption method/algorithm. The normal text is been encrypted and stored in a hash value.
jpascua
Posts: 197
Posted 03:27 May 06, 2015 |

http://www.xorbin.com/tools/sha256-hash-calculator

Are we supposed to generate the same hash value as that generated by this calculator? How are we expected to do this?

Hints would be appreciated!

Last edited by jpascua at 13:11 May 06, 2015.
ytsai8
Posts: 47
Posted 02:51 May 10, 2015 |

http://stackoverflow.com/questions/3103652/hash-string-via-sha-256-in-java

http://stackoverflow.com/questions/9655181/how-to-convert-a-byte-array-to-a-hex-string-in-java

http://www.sha1-online.com/sha256-java/

Here's some researching sources that I found useful. 

public static void main(String[] args) throws NoSuchAlgorithmException{
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        String str = "john@doe.com";
        md.update(str.getBytes());
        byte[] digest = md.digest();
        String check = bytesToHex(digest);
        System.out.println(check);
    }
    final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
    public static String bytesToHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for ( int j = 0; j < bytes.length; j++ ) {
            int v = bytes[j] & 0xFF;
            hexChars[j * 2] = hexArray[v >>> 4];
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }

This is the code that I end up combining all the sources, not sure if this is the most efficient way, but this works for me.