I have created a method in c# that takes unique email as input and returns base64 string. I am using MD5CryptoServiceProvider for this purpose. Here is the code:
public string GenerateHash(string str)
{
str = str.ToUpperInvariant();
MD5 md5 = new MD5CryptoServiceProvider();
byte[] emailBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
var base64Email = Convert.ToBase64String(emailBytes, 0, emailBytes.Length);
return RemoveSpecialCharacters(base64Email);
}
private static string RemoveSpecialCharacters(string str)
{
return Regex.Replace(str, "[^a-zA-Z0-9_.]+", "", RegexOptions.Compiled);
}
But the issue is it returns a string with special characters (eg /, ==) and I have to remove those special characters by myself using regex or something else but is there anyway I get a unique string without special characters so I don't have to use regex myself. Also is there any possibility I get a string of no more than 12 characters