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.
iot/projects/Infrastructure/Extensions/Md5Extensions.cs

28 lines
773 B

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace Infrastructure.Extensions
{
public static class Md5Extensions
{
public static string Md5(this Stream input)
{
using (MD5 md5 = MD5.Create())
{
byte[] hash = md5.ComputeHash(input);
return BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();
}
}
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).ToLower();
}
}
}
}