using System.Security.Cryptography;
public static void Main()
public static void Send()
string secretKey = "VinceIsCool";
string firstName = "Vince";
string lastName = "Zalamea";
string stringToHash = firstName + lastName + secretKey;
byte[] hash = MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(stringToHash));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
sb.Append(hash[i].ToString("X2"));
string digest = sb.ToString();
bool valid = Receive(firstName,lastName,digest);
Console.WriteLine("Receiver validated message integrity: " + valid);
public static bool Receive(string firstName, string lastName, string digest)
string secretKey = "VinceIsCool";
string stringToHash = firstName + lastName + secretKey;
byte[] hash = MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(stringToHash));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
sb.Append(hash[i].ToString("X2"));
string expectedDigest = sb.ToString();
return expectedDigest.Equals(digest);