當前位置: 首頁>>代碼示例>>Java>>正文


Java DigestInputStream.getMessageDigest方法代碼示例

本文整理匯總了Java中java.security.DigestInputStream.getMessageDigest方法的典型用法代碼示例。如果您正苦於以下問題:Java DigestInputStream.getMessageDigest方法的具體用法?Java DigestInputStream.getMessageDigest怎麽用?Java DigestInputStream.getMessageDigest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.DigestInputStream的用法示例。


在下文中一共展示了DigestInputStream.getMessageDigest方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: encode

import java.security.DigestInputStream; //導入方法依賴的package包/類
/**
 * 獲取文件的 MD5
 */
public static String encode(File file) {
    try {
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
        FileInputStream inputStream = new FileInputStream(file);
        DigestInputStream digestInputStream = new DigestInputStream(inputStream, messageDigest);
        //必須把文件讀取完畢才能拿到md5
        byte[] buffer = new byte[4096];
        while (digestInputStream.read(buffer) > -1) {
        }
        MessageDigest digest = digestInputStream.getMessageDigest();
        digestInputStream.close();
        byte[] md5 = digest.digest();
        StringBuilder sb = new StringBuilder();
        for (byte b : md5) {
            sb.append(String.format("%02X", b));
        }
        return sb.toString().toLowerCase();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:MD5Utils.java

示例2: getMd5

import java.security.DigestInputStream; //導入方法依賴的package包/類
public String getMd5(File f) throws IOException {

		FileInputStream in = new FileInputStream(f);
		DigestInputStream di = new DigestInputStream(in, md);

		byte[] buffer = new byte[bufferSize];
		while (di.read(buffer) > 0)
			;
		md = di.getMessageDigest();

		di.close();
		in.close();

		byte[] digest = md.digest();
		return byteArrayToHex(digest);
	}
 
開發者ID:huisongyang,項目名稱:fileserver,代碼行數:17,代碼來源:FileScan.java

示例3: hashStream

import java.security.DigestInputStream; //導入方法依賴的package包/類
public static String hashStream(InputStream input, byte[] buffer, String algorithm) throws IOException,NoSuchAlgorithmException {
DigestInputStream hasher = new DigestInputStream(input, MessageDigest.getInstance(algorithm));
 while(hasher.read(buffer) != -1)
     continue;
 MessageDigest hash = hasher.getMessageDigest();
 
 String retval = "";
 for(byte tohex : hash.digest())
     retval += String.format("%02x", tohex);

 return retval;
   }
 
開發者ID:kd0kfo,項目名稱:javalib,代碼行數:13,代碼來源:FileDigester.java

示例4: a

import java.security.DigestInputStream; //導入方法依賴的package包/類
public void a()
{
    if (j == null || !(new File(j)).exists())
    {
        Message message = l.obtainMessage();
        message.what = -5;
        message.obj = new String("");
        l.sendMessage(message);
        return;
    }
    k.onPrepareStart();
    File file = new File(j);
    m = file.length();
    try
    {
        MessageDigest messagedigest = MessageDigest.getInstance("SHA-1");
        FileInputStream fileinputstream = new FileInputStream(file);
        DigestInputStream digestinputstream = new DigestInputStream(fileinputstream, messagedigest);
        for (byte abyte0[] = new byte[0x80000]; digestinputstream.read(abyte0) > 0;) { }
        MessageDigest messagedigest1 = digestinputstream.getMessageDigest();
        n = DataConvert.toHexString(messagedigest1.digest());
        messagedigest1.reset();
        fileinputstream.close();
        digestinputstream.close();
    }
    catch (Exception exception)
    {
        Message message1 = l.obtainMessage();
        message1.what = -2;
        message1.obj = new String("");
        l.sendMessage(message1);
        return;
    }
    try
    {
        MessageDigest messagedigest2 = MessageDigest.getInstance("MD5");
        FileInputStream fileinputstream1 = new FileInputStream(file);
        DigestInputStream digestinputstream1 = new DigestInputStream(fileinputstream1, messagedigest2);
        for (byte abyte1[] = new byte[0x80000]; digestinputstream1.read(abyte1) > 0;) { }
        MessageDigest messagedigest3 = digestinputstream1.getMessageDigest();
        o = DataConvert.toHexString(messagedigest3.digest());
        messagedigest3.reset();
        fileinputstream1.close();
        digestinputstream1.close();
    }
    catch (Exception exception1)
    {
        Message message2 = l.obtainMessage();
        message2.what = -2;
        message2.obj = new String("");
        l.sendMessage(message2);
        return;
    }
    b();
}
 
開發者ID:vishnudevk,項目名稱:MiBandDecompiled,代碼行數:56,代碼來源:f.java


注:本文中的java.security.DigestInputStream.getMessageDigest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。