How to convert byte array to BigInteger in java

I am working on java ... I want to know how to convert an array of bytes to BigInteger. Actually, I used the md5 digest method, which returned me an array of bytes, which I want to convert to Biginteger.

+4
source share
2 answers

In this example, Get MD5 hash in multiple lines of Java has a related example.

I believe that 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 to print it in the style of "d41d8cd98f00b204e9800998ecf8427e" , you can do

 System.out.println(bi.toString(16)); 
+4
source

Actually, I used the md5 digest method, which returned me an array of bytes, which I want to convert to BigInteger .

You can use new BigInteger(byte[]) .

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

I think you are just doing this to print or order MD5 hashes. But there are fewer hungry opportunities to solve both problems.

+3
source

All Articles