Here you can find the source of digest(String provider, File file, int radix)
Parameter | Description |
---|---|
provider | the name of the provider (e.g., "MD5") for use in digesting the file. |
file | the file to digest. |
radix | the radix of the returned result. |
public static String digest(String provider, File file, int radix)
//package com.java2s; /*--------------------------------------------------------------- * Copyright 2009 by the Radiological Society of North America * * This source software is released under the terms of the * RSNA Public License (http://mirc.rsna.org/rsnapubliclicense) *----------------------------------------------------------------*/ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.math.BigInteger; import java.security.MessageDigest; public class Main { /**/*w w w . j a v a 2 s . c o m*/ * Digest a file with a specified provider. * @param provider the name of the provider (e.g., "MD5") * for use in digesting the file. * @param file the file to digest. * @param radix the radix of the returned result. * @return the digest of the file, converted to an integer * string in the specified radix, or the empty string if * an error occurs. */ public static String digest(String provider, File file, int radix) { String result; BufferedInputStream bis = null; try { MessageDigest messageDigest = MessageDigest.getInstance(provider); bis = new BufferedInputStream(new FileInputStream(file)); byte[] buffer = new byte[8192]; int n; while ((n = bis.read(buffer)) != -1) messageDigest.update(buffer, 0, n); byte[] hashed = messageDigest.digest(); BigInteger bi = new BigInteger(1, hashed); result = bi.toString(radix); } catch (Exception ex) { result = ""; } finally { try { bis.close(); } catch (Exception ignore) { } } return result; } }