import java.io.ByteArrayInputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;
public class DigestIO {
private static String message = "hello";
public static void main(String[] args) throws Exception {
ByteArrayInputStream bis = new ByteArrayInputStream(message.getBytes());
DigestInputStream dis = new DigestInputStream(bis,
MessageDigest.getInstance("SHA-256"));
byte[] b = new byte[1024];
int len = 0;
while ((len = dis.read(b)) != -1) {
System.out.println("读取了 ["+len+"] 个字节");
}
dis.close();
byte[] digest = dis.getMessageDigest().digest();
for (byte c : digest) {
System.out.println(c);
}
}
}
Java-IO之DigestInputStream sha256 计算hash值
最新推荐文章于 2024-08-21 03:57:22 发布