Java Code Examples for java.security.DigestInputStream#getMessageDigest()
The following examples show how to use
java.security.DigestInputStream#getMessageDigest() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileScan.java From fileserver with Apache License 2.0 | 6 votes |
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); }
Example 2
Source File: MD5Utils.java From okhttp-OkGo with Apache License 2.0 | 6 votes |
/** * 获取文件的 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; }
Example 3
Source File: f.java From MiBandDecompiled with Apache License 2.0 | 4 votes |
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(); }