/// <summary> /// To SHA1 /// </summary> /// <param name="data"></param> /// <param name="isUpper"></param> /// <param name="isIncludeHyphen"></param> /// <returns></returns> // ReSharper disable once InconsistentNaming public static string ToSHA1(this byte[] data, bool isUpper = true, bool isIncludeHyphen = false) { var hashBytes = SHA1HashingProvider.Signature(data); var str = BitConverter.ToString(hashBytes); return(str.ToFixUpperCase(isUpper).ToFixHyphenChar(isIncludeHyphen)); }
public static (string nonce, string timestamp, string signature) GenerateSignature(string appSecret) { var rd = new Random((int)DateTime.Now.Ticks); var rd_i = rd.Next(); var nonce = Convert.ToString(rd_i); var timestamp = Convert.ToString(ConvertDateTimeInt(DateTime.UtcNow)); var signature = SHA1HashingProvider.Signature(appSecret + nonce + timestamp); return(nonce, timestamp, signature); }
public void Test_Sha1_Base64() { var signature = SHA1HashingProvider.Signature("image", OutType.Base64); Assert.Equal("DnYpJ5SIjU8fp1+zr/TKJ8WPVqY=", signature); }
public void Test_Sha1_Hex() { var signature = SHA1HashingProvider.Signature("image"); Assert.Equal("0E76292794888D4F1FA75FB3AFF4CA27C58F56A6", signature); }
public void Test_Sha1_Base64() { var signature = SHA1HashingProvider.Signature("image", OutType.Base64); Assert.Equal("MGU3NjI5Mjc5NDg4OGQ0ZjFmYTc1ZmIzYWZmNGNhMjdjNThmNTZhNg==", signature); }
/// <summary> /// /// </summary> /// <param name="q_sign_algorithm">签名算法,目前仅支持 sha1</param> /// <param name="q_sign_time">签名有效起止时间,Unix时间戳,以秒为单位,;分隔</param> /// <param name="httpRequestInfo">HttpRequestInfo</param> /// <returns></returns> private static string GetStringToSign(string q_sign_algorithm, string q_sign_time, string httpRequestInfo) { return($"{q_sign_algorithm}\n{q_sign_time}\n{SHA1HashingProvider.Signature(httpRequestInfo, false)}\n".ToLower()); }
/// <summary> /// To SHA1 /// </summary> /// <param name="data"></param> /// <param name="isUpper"></param> /// <param name="isIncludeHyphen"></param> /// <param name="encoding"></param> /// <returns></returns> // ReSharper disable once InconsistentNaming public static string ToSHA1(this string data, bool isUpper = true, bool isIncludeHyphen = false, Encoding encoding = null) { return(SHA1HashingProvider.Signature(data, isUpper, isIncludeHyphen, encoding)); }