How to convert byte array to BigInteger in java

前端 未结 2 684
天命终不由人
天命终不由人 2021-02-09 15:04

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 co

2条回答
  •  佛祖请我去吃肉
    2021-02-09 15:38

    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));
    

提交回复
热议问题