/// <summary> /// 支付宝支付服务端签名生成 [REA] /// </summary> /// <param name="parameters">业务参数</param> /// <param name="privateKeyPem">REA私钥</param> /// <returns></returns> public static string SignAlipayPay(IDictionary <string, string> parameters, string privateKeyPem) { // 第一步:把字典按Key的字母顺序排序 IDictionary <string, string> sortedParams = new SortedDictionary <string, string>(parameters); IEnumerator <KeyValuePair <string, string> > dem = sortedParams.GetEnumerator(); // 第二步:把所有参数作为JSON串 StringBuilder query = new StringBuilder(); Dictionary <string, string> dic = new Dictionary <string, string>(); while (dem.MoveNext()) { string key = dem.Current.Key; object value = dem.Current.Value; query.Append(key); query.Append("="); query.Append("\"" + value + "\""); query.Append("&"); } var content = query.Remove(query.Length - 1, 1); var result = RSAFromPkcs8.sign(content.ToString(), privateKeyPem, "utf-8"); content.Append("&sign_type=\"RSA\"&sign=\"" + result + "\""); return(content.ToString()); }
/// <summary> /// 签名 /// </summary> /// <param name="content">待签名字符串</param> /// <param name="privateKey">私钥</param> /// <param name="input_charset">编码格式</param> /// <returns>签名后字符串</returns> public static string GetRSAFromPkcs8Sign(string content, string privateKey, string input_charset) { return(RSAFromPkcs8.sign(content, privateKey, input_charset)); }