-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCryptoUtils.cs
30 lines (29 loc) · 1.01 KB
/
CryptoUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
namespace Notpod
{
/// <summary>
/// Contains utiliy methods supporting the System.Security.Cryptography namespace.
/// </summary>
public class CryptoUtils
{
/// <summary>
/// Compute the MD5 hash and return it in hex format.
/// </summary>
/// <param name="original">The original string to compute the MD5 hash for.</param>
/// <returns>MD5 hex for the original string.</returns>
public static string Md5Hex(string original)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(original));
StringBuilder sb = new StringBuilder(32);
foreach (byte b in hash)
{
sb.Append(b.ToString("x2").ToUpper());
}
return sb.ToString().ToLower();
}
}
}