欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

md5sums,,public Strin

来源: javaer 分享于  点击 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
相关栏目:

用户点评