You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.1 KiB
27 lines
1.1 KiB
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace Infrastructure.Extensions
|
|
{
|
|
public static class Md5Extensions
|
|
{
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5351:不要使用损坏的加密算法", Justification = "<挂起>")]
|
|
public static string Md5(this Stream input)
|
|
{
|
|
using MD5 md5 = MD5.Create();
|
|
byte[] hash = md5.ComputeHash(input);
|
|
return BitConverter.ToString(hash).Replace("-", string.Empty, StringComparison.CurrentCulture).ToLower(CultureInfo.CurrentCulture);
|
|
}
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5351:不要使用损坏的加密算法", Justification = "<挂起>")]
|
|
public static string Md5(this string input)
|
|
{
|
|
using MD5 md5 = MD5.Create();
|
|
byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
|
|
return BitConverter.ToString(hash).Replace("-", string.Empty, StringComparison.CurrentCulture).ToLower(CultureInfo.CurrentCulture);
|
|
}
|
|
}
|
|
} |