public static string GetApiSignature(IDictionary <string, string> coll, string key) { var orgin = "POST&%2F&" + PercentEncode(string.Join("&", coll.OrderBy(x => x.Key, StringComparer.Ordinal).Select(x => $"{PercentEncode(x.Key)}={PercentEncode(x.Value)}"))); var sign = HMACSHA1HashingProvider.Signature(orgin, key + "&", Encoding.UTF8); // hex string to byte array var buffer = sign.HexToBytes(); // convert bytes to base64 string and return return(Convert.ToBase64String(buffer)); }
public void HmacSha1Test() { var signature = HMACSHA1HashingProvider.Signature("image", "alexinea"); Assert.Equal("0E5CF78AECFE44262169BB15003F97443E9DDFE3", signature); }
private static string Signature(this string orgin, string key) { return(HMACSHA1HashingProvider.Signature(orgin, $"{key}&", Encoding.UTF8)); }
/// <summary> /// 获取签名 /// </summary> /// <param name="stringToSign">StringToSign</param> /// <param name="signKey">SignKey</param> /// <returns></returns> private static string GetSignature(string stringToSign, string signKey) { return(HMACSHA1HashingProvider.Signature(stringToSign, signKey).ToLower()); }
/// <summary> /// /// </summary> /// <param name="q_key_time">Unix时间戳,以秒为单位,;分隔</param> /// <param name="secretKey">腾讯云API的SecretKey</param> /// <returns></returns> private static string GetSignKey(string q_key_time, string secretKey) { return(HMACSHA1HashingProvider.Signature(q_key_time, secretKey).ToLower()); }
public void Test_HmacSha1() { var signature = HMACSHA1HashingProvider.Signature("image", "jianxuanbing"); Output.WriteLine(signature); Assert.Equal("8D37923C16B438FC9B29462CB93723ADB46EF14A", signature); }