上传新文件时,如何同时获取文件MD5和SHA1校验和?
我正在使用存储系统.用户将文件上传到服务器.
I am working on a storage system. Users upload files to the server.
在服务器端,我想实现一个程序,以便同时使用MD5和SHA1获取文件的校验和.
On the server side, I want to implement a program to get the checksums of the file using both MD5 and SHA1.
我知道如何使用DigestInputStream函数计算校验和,但是似乎一次仅支持一种方法(MD5或SHA1). 在JAVA中处理上传流时,如何同时计算MD5和SHA1?
I know how to calculate checksums using DigestInputStream functions, but it seems only supports one method (either MD5 or SHA1) a time. How can I calculate both MD5 and SHA1 a the same time when dealing with the upload stream in JAVA?
谢谢大家
使用两个MessageDigest
实例(一个用于MD5,一个用于SHA1),并将读取的字节输入两个实例.
Use two MessageDigest
instances (one for MD5 and one for SHA1) and feed the bytes you read into both.