Last active
March 9, 2018 17:02
-
-
Save mikebridge/88ec929a01ef86c46df1b3a6982a76b5 to your computer and use it in GitHub Desktop.
Gravatar Hasher
This file contains hidden or 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.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