添加文件流md5计算
parent
c1d824ebf3
commit
c0af24c7fd
|
|
@ -6,6 +6,21 @@ namespace Infrastructure.Helpers
|
|||
{
|
||||
public class Md5
|
||||
{
|
||||
/// <summary>
|
||||
/// 计算字节流的MD5值
|
||||
/// </summary>
|
||||
public static string CalculateStreamMd5(Stream stream)
|
||||
{
|
||||
if (stream == null)
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
|
||||
if (!stream.CanRead)
|
||||
throw new InvalidOperationException("流不可读");
|
||||
|
||||
using var md5 = MD5.Create();
|
||||
var hashBytes = md5.ComputeHash(stream);
|
||||
return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
|
||||
}
|
||||
public static string Encrypt(string str)
|
||||
{
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue