Input Format

A single alphanumeric string denoting .

Constraints

  • String  consists of English alphabetic letters (i.e.,  and/or decimal digits (i.e.,  through ) only.

Output Format

Print the SHA-256 encryption value of  on a new line.


hackerrank java sha 256 solution


Java SHA 256 problem-solution | HackerRank

public static String GenerateHash(String input) throws NoSuchAlgorithmException {
        MessageDigest objSHA = MessageDigest.getInstance("SHA-256");
        byte[] bytSHA = objSHA.digest(input.getBytes());
        BigInteger intNumber = new BigInteger(1, bytSHA);
        String strHashCode = intNumber.toString(16);

        // pad with 0 if the hexa digits are less then 64.
        while (strHashCode.length() < 64) {
            strHashCode = "0" + strHashCode;
        }
        return strHashCode;
    }