patbef-ServiceOutside/ServiceShared/Crypto/MD5.cs

47 lines
1.3 KiB
C#
Raw Permalink Normal View History

2024-01-29 16:27:34 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServiceShared.Crypto
{
public static class MD5
{
/// <summary>
/// Encryptes a string value in md5 hash
/// </summary>
/// <param name="value">string value that should be encrypted in MD5 hash</param>
/// <returns>Returns MD5 hash</returns>
public static string Encrypt(string value)
{
string result = null;
try
{
byte[] bytes = Encoding.UTF8.GetBytes(value);
using (System.Security.Cryptography.MD5 hash = System.Security.Cryptography.MD5.Create())
{
byte[] hashedInputBytes = hash.ComputeHash(bytes);
StringBuilder hashedInputStringBuilder = new StringBuilder(128);
foreach (var b in hashedInputBytes)
{
hashedInputStringBuilder.Append(b.ToString("X2"));
}
result = hashedInputStringBuilder.ToString().ToLower();
}
}
catch
{
result = null;
}
return result;
}
}
}