using System.Security.Cryptography;
static string getAuthorizationHeader(string eventSlug, string method, string url, string user, string password, string body)
string passHash = sha256(eventSlug + password);
string authKey = sha256(user + passHash);
string hmacHash = CalcHMACSHA256Hash(method + url + body, authKey);
return "mobLee " + EncodeTo64(user + ":" + hmacHash);
static string sha256(string randomString)
var crypt = new System.Security.Cryptography.SHA256Managed();
var hash = new System.Text.StringBuilder();
byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(randomString));
foreach (byte theByte in crypto)
hash.Append(theByte.ToString("x2"));
private static string CalcHMACSHA256Hash(string plaintext, string salt)
var enc = Encoding.Default;
byte[] baText2BeHashed = enc.GetBytes(plaintext), baSalt = enc.GetBytes(salt);
System.Security.Cryptography.HMACSHA256 hasher = new HMACSHA256(baSalt);
byte[] baHashedText = hasher.ComputeHash(baText2BeHashed);
result = string.Join("", baHashedText.ToList().Select(b => b.ToString("x2")).ToArray());
static public string EncodeTo64(string toEncode)
byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);