Simple C# method to create the hash of the email address and return Gravatar image URL for a supplied email address. As per official documentation - https://en.gravatar.com/site/implement/images/
public static string GetGravatarImageUrl(string emailAddress) | |
{ | |
// Create MD5 Hash of email address | |
var md5 = System.Security.Cryptography.MD5.Create(); | |
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(emailAddress.Trim().ToLower()); | |
byte[] hash = md5.ComputeHash(inputBytes); | |
// Create lower-case hex string | |
var sb = new System.Text.StringBuilder(); | |
for (int i = 0; i < hash.Length; i++) | |
{ | |
sb.Append(hash[i].ToString("x2")); | |
} | |
// Build URL | |
return string.Concat("http://www.gravatar.com/avatar/", sb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment