本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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();
}