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

  • SEARCH
  • Home
  • 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 8829481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:50:32+00:00 2026-06-14T07:50:32+00:00

I am using following code to generate MD5 Hash for my application it encodes

  • 0

I am using following code to generate MD5 Hash for my application it encodes some string value and then I send this generated hash through my web service to some .Net code, that code read my MD5 hash and generate MD5 of the string the strings he is getting from DB and then compare them

public static String getMD5Hash(String val) throws Exception {
        byte[] bytes = val.getBytes();

        MessageDigest m = MessageDigest.getInstance("MD5");
        byte[] digest = m.digest(bytes);
        String hash = new BigInteger(1, digest).toString(16);
        System.out.println(hash.length());
        return hash;
    }

    public static void main(String[] asd) throws Exception{
        for(int i=0;i<10;i++){
            System.out.println(getMD5Hash(i+Math.pow(10, i)+""));//for testing
            System.out.println(getMD5Hash(i+""));//for testing
        }
    }

The issue is as i am getting converted hash from BigInteger and some times generated hash starts with a 0 in that case Biginteger does not consider that 0 and on the other side when .Net generates that hash of the same string it generate it with 0 and in this way string comparison return false, e-g
hash code i generate and send “102678D1922799CF9122B3F103975F1” where in .Net hash is “0102678D1922799CF9122B3F103975F1”

also some times it generate code like

.Net generates  0012678D1922799CF9122B3F103975F1 and java 12678D1922799CF9122B3F103975F1 

OR

0002678D1922799CF9122B3F103975F1 and 2678D1922799CF9122B3F103975F1

How can i get this code with all 0s that are in start.
Thanks in advance.

  • 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-06-14T07:50:34+00:00Added an answer on June 14, 2026 at 7:50 am

    This question has some better methods of generating the hex string:

    In Java, how do I convert a byte array to a string of hex digits while keeping leading zeros?

    Since you’re already using BigInteger, this seems like the best solution:

    BigInteger bi = new BigInteger(1, digest);
    String hash = String.format("%0" + (digest.length << 1) + "X", bi);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code to generate excel from sql through php.this is
I generate a vcard that I send to the client using the following code
All, I'm using the following code to generate some li items in an ol.
I'm using the following code to generate a random string: <?php function random_string( )
Iam using following code to generate CAPTCHA : $captcha = $this->createElement('captcha', 'captcha', array('required' =>
I'm having some issues here. I am using the following code to generate the
I am using the following code to generate a histogram chart using YUI charts:
I am using the following code to generate an encrypted token: var ticket =
I am using the following code to generate a Buy Now button for selling
I'm using the following code which will generate a wav file which contains a

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.