Java SHA 256 Hacker Rank Solution

Hello coders, In this post, you will learn how to solve Java SHA 256 Hacker Rank Solution. This problem is a part of the Java programming series. 

One more thing to add, don’t straight away look for the solutions, first try to solve the problems by yourself. If you find any difficulty after trying several times, then look for the solutions.

Java SHA 256 Hacker Rank Solution
Java SHA 256 Hacker Rank Solution

Java SHA 256 Hacker Rank Solution


Cryptographic hash functions are mathematical operations run on digital data; by comparing the computed hash (i.e., the output produced by executing a hashing algorithm) to a known and expected hash value, a person can determine the data’s integrity. For example, computing the hash of a downloaded file and comparing the result to a previously published hash result can show whether the download has been modified or tampered with. In addition, cryptographic hash functions are extremely collision-resistant; in other words, it should be extremely difficult to produce the same hash output from two different input values using a cryptographic hash function.

Secure Hash Algorithm 2 (SHA-2) is a set of cryptographic hash functions designed by the National Security Agency (NSA). It consists of six identical hashing algorithms (i.e., SHA-256SHA-512SHA-224SHA-384SHA-512/224SHA-512/256) with a variable digest size. SHA-256 is a -bit ( byte) hashing algorithm which can calculate a hash code for an input of up to  bits. It undergoes  rounds of hashing and calculates a hash code that is a -digit hexadecimal number.

Given a string, , print its SHA-256 hash value.

Input Format

A single alphanumeric string denoting .


  • 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.

Sample Input 0


Sample Output 0


Sample Input 1


Sample Output 1


Java SHA 256 Hacker Rank Solution

import java.util.Scanner;
public class Solution {
    public static void main(String[] args) throws NoSuchAlgorithmException {
        Scanner scan = new Scanner(;
        String str =;
        /* Encode the String using SHA-256 */
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        byte[] digest = md.digest();
        /* Print the encoded value in hexadecimal */
        for (byte b : digest) {
            System.out.format("%02x", b);

Disclaimer: The above Problem (Java SHA 256) is generated by Hackerrank but the Solution is Provided by Chase2Learn. This tutorial is only for Educational and Learning purposes. Authority if any of the queries regarding this post or website fill the following contact form thank you.

Sharing Is Caring

Leave a Comment