这会给128位哈希吗?

时间:2011-11-23 21:29:50

标签: java hash

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

如果没有,我会在哪里设置?谢谢

1 个答案:

答案 0 :(得分:1)

没有。 SHA1 returns 160 bits(20字节)哈希。