Skip to content

Instantly share code, notes, and snippets.

@mikebridge
Last active March 9, 2018 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikebridge/88ec929a01ef86c46df1b3a6982a76b5 to your computer and use it in GitHub Desktop.
Save mikebridge/88ec929a01ef86c46df1b3a6982a76b5 to your computer and use it in GitHub Desktop.
Gravatar Hasher
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace Common
{
public static class GravatarHasher
{
/// <summary>
/// Create a gravatar hash (or null)
/// SEE: https://en.gravatar.com/site/implement/hash/
/// </summary>
public static string GravatarHash(String email)
{
if (email == null)
{
return null;
}
var canonicalEmail = email.Trim().ToLower();
var inputBytes = Encoding.ASCII.GetBytes(canonicalEmail);
var hash = MD5.Create().ComputeHash(inputBytes);
return String.Join("", hash.Select(x => x.ToString("x2")));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment