Will this give a 128 bit Hash?

2019-04-15 21:54发布

    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("SHA-1");
    }
    catch(NoSuchAlgorithmException e) {
        e.printStackTrace();
    } 

    String hashToConvert = byteArrayToHexBigInt(md.digest(objectName));

    /*
     * Converts to big Integer, will not be concatted because structure
     * is large enough to hold the Hash created
     * Second argument is set to 16 as this is the base for the parsing of the
     * hash to convert
     */
    BigInteger bigHash = new BigInteger(hashToConvert, 16);

    return bigHash;

}


public static String byteArrayToHexBigInt(byte[] b) throws Exception {
      String result = "";
      for (int i=0; i < b.length; i++) {
        result +=
              Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
      }
      return result;
    }

If not where would I set this? Thanks

标签: java hash
1条回答
不美不萌又怎样
2楼-- · 2019-04-15 22:15

No. SHA1 returns 160 bits (20 bytes) hash.

查看更多
登录 后发表回答