Created
December 9, 2016 11:17
-
-
Save David-Mimnagh/209cd55c9a785706bde3c0ac61cd92aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Security.Cryptography; | |
namespace AdventOfCode_Day5 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string source = "abc";// "wtnhxymk"; | |
using (MD5 md5Hash = MD5.Create()) | |
{ | |
string hash = GetMd5Hash(md5Hash, source); | |
Console.WriteLine("The MD5 hash of " + source + " is: " + hash + "."); | |
} | |
Console.Read(); | |
} | |
static string GetMd5Hash(MD5 md5Hash, string input) | |
{ | |
// Convert the input string to a byte array and compute the hash. | |
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); | |
// Create a new Stringbuilder to collect the bytes | |
// and create a string. | |
StringBuilder sBuilder = new StringBuilder(); | |
// Loop through each byte of the hashed data | |
// and format each one as a hexadecimal string. | |
for (int i = 0; i < data.Length; i++) | |
{ | |
sBuilder.Append(data[i].ToString("x2")); | |
} | |
// Return the hexadecimal string. | |
return sBuilder.ToString(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment