标签:
public static void main(String[] args) throws Exception {
byte[] bytes = "测试".getBytes();
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(bytes);
MessageDigest messageDigest1 = MessageDigest.getInstance("MD5");
DigestInputStream digestInputStream = new DigestInputStream(new ByteArrayInputStream(bytes), messageDigest1);
digestInputStream.read(bytes, 0, bytes.length);
System.out.println(MessageDigest.isEqual(messageDigest.digest(), digestInputStream.getMessageDigest().digest()));
digestInputStream.close();
MessageDigest messageDigest2 = MessageDigest.getInstance("MD5");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
System.out.println(byteArrayOutputStream.toString());
DigestOutputStream digestOutputStream = new DigestOutputStream(byteArrayOutputStream, messageDigest2);
digestOutputStream.write(bytes, 0, bytes.length);
digestOutputStream.getMessageDigest().digest();
System.out.println(byteArrayOutputStream.toString());
digestOutputStream.flush();
digestOutputStream.close();
}
true 测试
MessageDigest、DigestInputStream、DigestOutputStream简介
标签:
原文地址:http://www.cnblogs.com/gjb724332682/p/5500687.html