md5sums,,public Strin
分享于 点击 24252 次 点评:11
md5sums,,public Strin
public String md5sums(InputStream is) throws NoSuchAlgorithmException, FileNotFoundException{ MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] buffer = new byte[8192]; int read = 0; String md5sums = ""; try { while( (read = is.read(buffer)) > 0) { digest.update(buffer, 0, read); } byte[] md5sum = digest.digest(); BigInteger bigInt = new BigInteger(1, md5sum); md5sums = bigInt.toString(16); } catch(IOException e) { throw new RuntimeException("Unable to process file for MD5", e); } finally { try { is.close(); } catch(IOException e) { throw new RuntimeException("Unable to close input stream for MD5 calculation", e); } } return md5sums;}//该片段来自于http://byrx.net
用户点评