public static bool TryParse(string input, out ApiRequestSignature parsedValue) { parsedValue = null; var success = false; if (input != null) { var parts = input.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 3) { if (parts[2].Length == 64) { DateTime timestamp; if (DateTime.TryParseExact( parts[1], "o", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out timestamp)) { parsedValue = new ApiRequestSignature { AppId = parts[0], TimestampString = parts[1], Hash = parts[2], Timestamp = timestamp, }; success = true; } } } } return(success); }
private void AddAuthorization(HttpRequestMessage request) { if (_options != null) { var signature = new ApiRequestSignature { AppId = _options.AppId }; var parameters = new[] { new NameValuePair(null, _options.AppId), new NameValuePair(null, signature.TimestampString) }; signature.Hash = HmacUtility.GetHashString(key => new HMACSHA256(key), _options.SecretKey, parameters); request.Headers.Authorization = new AuthenticationHeaderValue("HMACSHA256", signature.ToString()); } }