public string Compose(string canonicalizedRequest, DateTime dateTime, EscherConfig config) { return(String.Join("\n", new string[] { config.AlgorithmPrefix.ToUpper() + "-HMAC-" + config.HashAlgorithm.ToUpper(), dateTime.ToEscherLongDate(), dateTime.ToEscherShortDate() + "/" + config.CredentialScope, HashHelper.Hash(canonicalizedRequest, config.HashAlgorithm) })); }
public string Compose(EscherConfig config, string key, DateTime dateTime, string[] headersToSign, string stringToSign, string secret) { Array.Sort(headersToSign, StringComparer.Ordinal); return(String.Join(" ", new[] { config.AlgorithmPrefix + "-HMAC-" + config.HashAlgorithm.ToUpper(), string.Format("Credential={0}/{1}/{2},", key, dateTime.ToEscherShortDate(), config.CredentialScope), string.Format("SignedHeaders={0},", String.Join(";", headersToSign.Select(h => h.ToLower()))), "Signature=" + SignatureCalculator.Sign(stringToSign, secret, dateTime, config) })); }
public string Canonicalize(IEscherRequest request, string[] headersToSign, EscherConfig config) { headersToSign = headersToSign.Select(h => h.ToLower()).ToArray(); return(String.Join("\n", new[] { request.Method.ToUpper(), request.Uri.AbsolutePath, CanonicalizeQueryString(request.Uri), }.Concat(CanonicalizeHeaders(request, headersToSign)).Concat(new[] { null, String.Join(";", headersToSign.OrderBy(s => s)), HashHelper.Hash(request.Body, config.HashAlgorithm) }))); }
public static string Sign(string stringToSign, string secret, DateTime dateTime, EscherConfig config) { var hmac = HashHelper.GetHMacImplementation(config.HashAlgorithm); hmac.Key = Encoding.UTF8.GetBytes(config.AlgorithmPrefix + secret); hmac.Key = hmac.ComputeHash(Encoding.UTF8.GetBytes(dateTime.ToEscherShortDate())); foreach (var credentialScopePart in config.CredentialScope.Split('/')) { hmac.Key = hmac.ComputeHash(Encoding.UTF8.GetBytes(credentialScopePart)); } return(HashHelper.ByteArrayToHexaString(hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign)))); }