Created
March 31, 2013 22:14
-
-
Save rikkit/5282217 to your computer and use it in GitHub Desktop.
Simple class to get a a Gravatar URI in WinRT
This file contains 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 Windows.Security.Cryptography; | |
using Windows.Security.Cryptography.Core; | |
namespace IF.Utilities.Common | |
{ | |
public class Gravatar | |
{ | |
private const string GravatarFormatString = "http://www.gravatar.com/avatar/{0}.jpg?d=retro&r=g&s={1}"; | |
public static Uri GetGravatarUri(string email, int width = 80) | |
{ | |
var hash = email.HashMD5(); | |
var uri = string.Format(GravatarFormatString, hash, width); | |
return new Uri(uri); | |
} | |
} | |
public static class Md5Ex | |
{ | |
public static string HashMD5(this string str) | |
{ | |
var alg = HashAlgorithmProvider.OpenAlgorithm("MD5"); | |
var buff = CryptographicBuffer.ConvertStringToBinary(str, BinaryStringEncoding.Utf8); | |
var hashed = alg.HashData(buff); | |
var res = CryptographicBuffer.EncodeToHexString(hashed); | |
return res; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment