Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

47 lines
1.4 KiB

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Security.Cryptography;
using System.Text;
namespace Squidex.Infrastructure
{
public static class GravatarHelper
{
public static string CreatePictureUrl(string email)
{
var gravatarUrl = $"https://www.gravatar.com/avatar/{Hash(email)}";
return gravatarUrl;
}
public static string CreateProfileUrl(string email)
{
var gravatarUrl = $"https://www.gravatar.com/{Hash(email)}";
return gravatarUrl;
}
private static string Hash(string email)
{
using (var md5 = MD5.Create())
{
var normalizedEmail = email.ToLowerInvariant().Trim();
var hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(normalizedEmail));
var hashBuilder = new StringBuilder();
for (var i = 0; i < hashBytes.Length; i++)
{
hashBuilder.Append(hashBytes[i].ToString("x2"));
}
return hashBuilder.ToString();
}
}
}
}