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.
42 lines
1.2 KiB
42 lines
1.2 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Security.Cryptography; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
|
|
namespace AttachmentDemo.Helper |
|
{ |
|
public class Md5Helper |
|
{ |
|
public static string Md5(string value) |
|
{ |
|
var result = string.Empty; |
|
if (string.IsNullOrEmpty(value)) return result; |
|
using (var md5 = MD5.Create()) |
|
{ |
|
result = GetMd5Hash(md5, value); |
|
} |
|
return result; |
|
} |
|
|
|
|
|
static string GetMd5Hash(MD5 md5Hash, string input) |
|
{ |
|
|
|
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); |
|
var sBuilder = new StringBuilder(); |
|
foreach (byte t in data) |
|
{ |
|
sBuilder.Append(t.ToString("x2")); |
|
} |
|
return sBuilder.ToString(); |
|
} |
|
static bool VerifyMd5Hash(MD5 md5Hash, string input, string hash) |
|
{ |
|
var hashOfInput = GetMd5Hash(md5Hash, input); |
|
var comparer = StringComparer.OrdinalIgnoreCase; |
|
return 0 == comparer.Compare(hashOfInput, hash); |
|
} |
|
} |
|
}
|
|
|