Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 933961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:55:07+00:00 2026-05-15T20:55:07+00:00

I know this sounds like a broad question but I can narrow it down

  • 0

I know this sounds like a broad question but I can narrow it down with an example. I am VERY new at Java. For one of my “learning” projects, I wanted to create an in-house MD5 file hasher for us to use. I started off very simple by attempting to hash a string and then moving on to a file later. I created a file called MD5Hasher.java and wrote the following:

import java.security.*;
import java.io.*;
public class MD5Hasher{
    public static void main(String[] args){
        String myString = "Hello, World!";
        byte[] myBA = myString.getBytes();
        MessageDigest myMD;
        try{
            myMD = MessageDigest.getInstance("MD5");
            myMD.update(myBA);
            byte[] newBA = myMD.digest();
            String output = newBA.toString();
            System.out.println("The Answer Is: " + output);
        } catch(NoSuchAlgorithmException nsae){
            // print error here
        }
    }
}

I visited java.sun.com to view the javadocs for java.security to find out how to use MessageDigest class. After reading I knew that I had to use a “getInstance” method to get a usable MessageDigest object I could use. The Javadoc went on to say “The data is processed through it using the update methods.” So I looked at the update methods and determined that I needed to use the one where I fed it a byte array of my string, so I added that part. The Javadoc went on to say “Once all the data to be updated has been updated, one of the digest methods should be called to complete the hash computation.” I, again, looked at the methods and saw that digest returned a byte array, so I added that part. Then I used the “toString” method on the new byte array to get a string I could print. However, when I compiled and ran the code all that printed out was this:

The Answer Is: [B@4cb162d5

I have done some looking around here on StackOverflow and found some information here:

How can I generate an MD5 hash?

that gave the following example:

String plaintext = 'your text here';
MessageDigest m = MessageDigest.getInstance("MD5");
m.reset();
m.update(plaintext.getBytes());
byte[] digest = m.digest();
BigInteger bigInt = new BigInteger(1,digest);
String hashtext = bigInt.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
while(hashtext.length() < 32 ){
    hashtext = "0"+hashtext;
}

It seems the only part I MAY be missing is the “BigInteger” part, but I’m not sure.

So, after all of this, I guess what I am asking is, how do you know to use the “BigInteger” part? I wrongly assumed that the “toString” method on my newBA object would convert it to a readable output, but I was, apparently, wrong. How is a person supposed to know which way to go in Java? I have a background in C so this Java thing seems pretty weird. Any advice on how I can get better without having to “cheat” by Googling how to do something all the time?

Thank you all for taking the time to read. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:55:08+00:00Added an answer on May 15, 2026 at 8:55 pm

    You have actually successfully digested the message. You just don’t know how to present the found digest value properly. What you have is a byte array. That’s a bit difficult to read, and a toString of a byte array yields [B@somewhere which is not useful at all.

    The BigInteger comes into it as a tool to format the byte array to a single number.

    What you do is:

    • construct a BigInteger with the proper value (in this case that value happens to be encoded in the form of a byte array – your digest
    • Instruct the BigInteger object to return a String representation (e.g. plain, readable text) of that number, base 16 (e.g. hex)

    And the while loop prefixes that value with 0-characters to get a width of 32. I’d probably use String.format for that, but whatever floats your boat 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this sounds like a dumb question but I need to ask this.
I know this sounds like something I can google, but the truth is that
I know this sounds like an easy question but for some reason I just
I know this sounds like a stupid question, but I really don't see the
Sorry if this sounds like a newbie question, but the other day a Java
I know this sounds like a really obvious question, but it's proving harder to
I know this sounds like a simple question, but I just wasted the last
I know this sounds like a dumb question, but it's to settle an argument
I know this may sounds like a pointless question, but hear me out... I
I know this sounds like a stupid question, but here it is: Is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.