Example #1
0
        public string RSASign(IDictionary <string, string> parameters, string privateKeyPem, string charset,
                              string signType)
        {
            var signContent = ToStringContent(parameters);

            return(AlipaySignature.RSASignCharSet(signContent, privateKeyPem, charset, signType));
        }
Example #2
0
        public bool RSACheckV1(IDictionary <string, string> parameters, string publicKeyPem, string charset)
        {
            var sign = parameters["sign"];

            parameters.Remove("sign");
            parameters.Remove("sign_type");
            var signContent = ToStringContent(parameters);

            return(AlipaySignature.RSACheckContent(signContent, sign, publicKeyPem, charset, "RSA", true));
        }
Example #3
0
        public static void CheckResponseSign(string sign, string signSourceDate, AlipayFormSetting setting)
        {
            if (string.IsNullOrEmpty(setting.PublicKey) || string.IsNullOrEmpty(setting.Charset))
            {
                throw new AliPayException("public key or charset is Empty!");
            }

            if (signSourceDate == null)
            {
                throw new AliPayException("sign check fail: sign is Empty!");
            }

            var rsaCheckContent = AlipaySignature.RSACheckContent(signSourceDate, sign, setting.PublicKey,
                                                                  setting.Charset, setting.SignType);

            if (!rsaCheckContent)
            {
                throw new AliPayException("sign check fail: check Sign and Data Fail!");
            }
        }
Example #4
0
        public static void CheckResponseSign(string sign, string signSourceDate, AlipayFormSetting setting)
        {
            if (string.IsNullOrEmpty(setting.PublicKey) || string.IsNullOrEmpty(setting.Charset))
            {
                throw new AliPayException("public key or charset is Empty!");
            }

            if (signSourceDate == null)
            {
                throw new AliPayException("sign check fail: sign is Empty!");
            }

            var rsaCheckContent = AlipaySignature.RSACheckContent(signSourceDate, sign, "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlLPFduIFgSUbSLCyHTnvdQvLfU8kR8i/6OSMjnfcoIl0ROMAAdcv7JWD1BzqMTXfvZrmFWj4yuznSqNpdqoL11lQ35EGMZSHntsu5tpCg+9iguhBnTgHn+wr7pYxF9SfJU/6MxYdfArtcyx5FzKLrtpuVkDQZRavIrfoB49NJRXzV4bMPAvhnB3k/O9xwkT1UAh5gbqbaKKYdymInKmstrhQ5kqKCSQey4js/zM14y9SXXyxIHO6BGEGWepmym/2C2BDhMqANnujHZq4bEtsV+aTob5BDA6FcPijMUrlUcFCqParu4c4X0FlhoHsG0vm5owfjpjMsetggmPKR1nzQwIDAQAB",
                                                                  setting.Charset, setting.SignType, false);

            if (!rsaCheckContent)
            {
                throw new AliPayException("sign check fail: check Sign and Data Fail!");
            }
        }
Example #5
0
        private static AopDictionary RequestBase(AlipayFormSetting setting, string method)
        {
            if (string.IsNullOrEmpty(setting.APPId))
            {
                throw new AliPayException("您的支付宝配置未能通过检查,详细信息:商户ID未指定!");
            }

            //SignType私钥检查
            if (string.IsNullOrEmpty(setting.SignType))
            {
                throw new AliPayException("您的支付宝配置未能通过检查,详细信息:签名类型未指定!");
            }

            //RSA私钥检查
            if (string.IsNullOrEmpty(setting.PrivateKey))
            {
                throw new AliPayException("您的支付宝配置未能通过检查,详细信息:未能获取到商户私钥!");
            }

            //RSA私钥格式检查
            RSA rsaCsp = AlipaySignature.LoadCertificateString(setting.PrivateKey, setting.SignType);

            if (rsaCsp == null)
            {
                throw new AliPayException("您的支付宝配置未能通过检查,详细信息:商户私钥格式错误,未能导入!");
            }

            var dic = new AopDictionary();

            dic.Add("app_id", setting.APPId);
            dic.Add("method", method);
            dic.Add("format", setting.Format);
            dic.Add("charset", setting.Charset);
            dic.Add("sign_type", setting.SignType);
            dic.Add("timestamp", DateTime.Now);
            dic.Add("version", setting.Version);

            return(dic);
        }