Java MD5 | HackerRank Solution

Hello coders, today we are going to solve Java MD5 HackerRank Solution.

Java MD5


MD5 (Message-Digest algorithm 5) is a widely-used cryptographic hash function with a -bit hash value. Here are some common uses for MD5:

  • To store a one-way hash of a password.
  • To provide some assurance that a transferred file has arrived intact.

MD5 is one in a series of message digest algorithms designed by Professor Ronald Rivest of MIT (Rivest, 1994); however, the security of MD5 has been severely compromised, most infamously by the Flame malware in 2012. The CMU Software Engineering Institute essentially considers MD5 to be “cryptographically broken and unsuitable for further use”.
Given an alphanumeric string, s, denoting a password, compute and print its MD5 encryption value.

Input Format

A single alphanumeric string denoting s.


  • 6 <= |s| <= 20
  • String s consists of English alphabetic letters (i.e.,[a-z A-Z] and/or decimal digits (i.e.,0 through 9) only.

Output Format

Print the MD5 encryption value of s on a new line.

Sample Input 0


Sample Output 0


Sample Input 1


Sample Output 1


Solution – Java MD5

import java.util.Scanner;

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

Disclaimer: The above Problem ( Java MD5 ) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published.