Java MD5 String md5(InputStream is)

Here you can find the source of md5(InputStream is)

Description

md

License

Open Source License

Declaration

private static String md5(InputStream is) throws Exception 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009 Richard Malek and SEAGE contributors
    //w ww . j  a va 2  s  . c  om
 * This file is part of SEAGE.
    
 * SEAGE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
    
 * SEAGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
    
 * You should have received a copy of the GNU General Public License
 * along with SEAGE. If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.io.InputStream;

import java.math.BigInteger;
import java.security.MessageDigest;

public class Main {
    private static String md5(InputStream is) throws Exception {
        MessageDigest digest = MessageDigest.getInstance("MD5");
        byte[] buffer = new byte[8192];
        int read = 0;

        while ((read = is.read(buffer)) > 0) {
            digest.update(buffer, 0, read);
        }
        byte[] md5sum = digest.digest();
        BigInteger bigInt = new BigInteger(1, md5sum);
        String output = bigInt.toString(16);

        is.close();

        return output;
    }
}

Related

  1. md5(final String str)
  2. md5(final String string)
  3. md5(final String string)
  4. md5(final String text)
  5. md5(InputStream input)
  6. md5(java.lang.String message)
  7. md5(Object content)
  8. md5(Path path)
  9. md5(String content)