Skip to content

Instantly share code, notes, and snippets.


sbosell/md5.cs Secret

Last active January 31, 2022 01:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Ambient Data Example Md5
// Full visual studio example can be found @
using ServiceStack;
using System.Text;
// Hard coded for simplicity
// No Error checking you'll want to ensure the file exists/etc
var inputFile = "d:\\temp\\emails.csv";
var outputFile = inputFile.Replace(".csv", "-hashed.csv");
// ServiceStack.Text string extensions rock
var csv = inputFile.ReadAllText();
// ServiceStack.Text has some nifty methods to make converting from csv/json/etc very easy
var data = csv.FromCsv<List<CsvReader>>();
// Select and Hash each email
List<CsvWriter> output = data.Select(d => new CsvWriter() { Hash = d.Email.ToLower().MD5() }).ToList();
// Write them all to the output file
File.WriteAllText(outputFile, output.ToCsv());
public class CsvReader
public string Email { get; set; } = String.Empty;
// The output class is just one column hashed
public class CsvWriter
public string Hash { get; set; } = String.Empty;
public static class Helpers
public static string MD5(this string s)
using var provider = System.Security.Cryptography.MD5.Create();
StringBuilder builder = new StringBuilder();
foreach (byte b in provider.ComputeHash(Encoding.UTF8.GetBytes(s)))
return builder.ToString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment