Skip to content

Instantly share code, notes, and snippets.

@rikkit
Created March 31, 2013 22:14
Show Gist options
  • Save rikkit/5282217 to your computer and use it in GitHub Desktop.
Save rikkit/5282217 to your computer and use it in GitHub Desktop.
Simple class to get a a Gravatar URI in WinRT
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