- 论坛徽章:
- 0
|
想直接计算ByteArrayInputStream 的MD5值,不想使用FileInputStream 因为每次都要生成一个文件。各位大侠有是否有好办法?
每次都说我算的MD5不对。。。郁闷。- private static String computeContentMD5HeaderValue(InputStream in)
- throws IOException, NoSuchAlgorithmException
- {
- in.reset();
- DigestInputStream dis = new DigestInputStream(fis, MessageDigest
- .getInstance("MD5"));
- byte[] buffer = new byte[8192];
- while (dis.read(buffer) > 0)
- ;
- String md5Content = new String(org.apache.commons.codec.binary.Base64
- .encodeBase64(dis.getMessageDigest().digest()));
- in.reset();
- return md5Content;
- }
复制代码 |
|