Will this give a 128 bit Hash?

巧了我就是萌 提交于 2020-01-01 19:43:44

问题


    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


回答1:


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



来源:https://stackoverflow.com/questions/8249334/will-this-give-a-128-bit-hash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!