上传新文件时,如何同时获取文件MD5和SHA1校验和? [英] How to get File both MD5 and SHA1 checksum at the same time when upload a new file?

查看:304
本文介绍了上传新文件时,如何同时获取文件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.

这篇关于上传新文件时,如何同时获取文件MD5和SHA1校验和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆