8

I'm working on java... I want to know how to convert array of byte into BigInteger. Actually i used md5's digest method which returned me array of byte which i want to convert into Biginteger.

1
  • @Stephen C :) :) , I meant in which manner particularly, It can be simple array of byte[] also String content's byte representation Commented Nov 15, 2010 at 6:54

2 Answers 2

8

This example Get MD5 hash in a few lines of Java has a related example.

I believe you should be able to do

MessageDigest m=MessageDigest.getInstance("MD5");
m.update(message.getBytes(), 0, message.length());
BigInteger bi = new BigInteger(1,m.digest());

and if you want it printed in the style "d41d8cd98f00b204e9800998ecf8427e" you should be able to do

System.out.println(bi.toString(16));
Sign up to request clarification or add additional context in comments.

Comments

5

Actually i used md5's digest method which returned me array of byte which i want to convert into a BigInteger.

You can use new BigInteger(byte[]).

However, it should be noted that the MD5 hash is not really an integer in any useful sense. It is really just a binary bit pattern.

I guess you are just doing this so that you can print or order the MD5 hashes. But there are less memory hungry ways of accomplishing both tasks.

1 Comment

better to use the integer,byte[] constructor. this one will interpret it as a two's complement binary representation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.