Esempio n. 1
0
        //RSA签名
        private static String addSignRSA(SortedDictionary <string, string> sParaTemp, String rsa_private)
        {
            string oid_partner;

            sParaTemp.TryGetValue("sign_type", out oid_partner);
            Console.WriteLine("进入商户[" + oid_partner + "]MD5加签名");

            if (sParaTemp == null)
            {
                return("");
            }
            // 生成签名原串
            String sign_src = genSignData(sParaTemp);

            Console.WriteLine("商户[" + oid_partner + "]加签原串"
                              + sign_src);
            Console.WriteLine("RSA签名key:" + rsa_private);
            try
            {
                string sign = RSAFromPkcs8.sign(sign_src, rsa_private, "utf-8");
                Console.WriteLine("商户[" + oid_partner + "]签名结果"
                                  + sign);
                return(sign);
            } catch (Exception e)
            {
                Console.WriteLine("商户[" + oid_partner + "]RSA加签名异常" + e.Message);
                return("");
            }
        }
Esempio n. 2
0
        //RSA验签
        private static bool checkSignRSA(SortedDictionary <string, string> sParaTemp, String rsa_public)
        {
            string oid_partner;

            sParaTemp.TryGetValue("sign_type", out oid_partner);
            Console.WriteLine("进入商户[" + oid_partner + "]MD5签名验证");

            if (sParaTemp == null)
            {
                return(false);
            }
            String sign;

            if (!sParaTemp.TryGetValue("sign", out sign))
            {
                return(false);
            }

            // 生成签名原串
            String sign_src = genSignData(sParaTemp);

            Console.WriteLine("商户[" + oid_partner + "]待签名原串"
                              + sign_src);
            Console.WriteLine("商户[" + oid_partner + "]签名串"
                              + sign);
            try
            {
                if (RSAFromPkcs8.verify(sign_src, sign, rsa_public, "UTF-8"))
                {
                    Console.WriteLine("商户[" + oid_partner
                                      + "]RSA签名验证通过");
                    return(true);
                }
                else
                {
                    Console.WriteLine("商户[" + oid_partner
                                      + "]RSA签名验证未通过");
                    return(false);
                }
            } catch (Exception e)
            {
                Console.WriteLine("商户[" + oid_partner
                                  + "]RSA签名验证异常" + e.Message);
                return(false);
            }
        }