Esempio n. 1
0
        //MD5签名
        private static String addSignMD5(SortedDictionary <string, string> sParaTemp, String md5_key)
        {
            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("MD5签名key:" + md5_key);

            sign_src += "&key=" + md5_key;

            try
            {
                string sign = Md5Algorithm.getInstance().md5Digest(
                    Encoding.UTF8.GetBytes(sign_src));
                Console.WriteLine("商户[" + oid_partner + "]签名结果"
                                  + sign);
                return(sign);
            } catch (Exception e)
            {
                Console.WriteLine("商户[" + oid_partner
                                  + "] MD5加签名异常" + e.Message);
                return("");
            }
        }
Esempio n. 2
0
        //MD5验签
        private static bool checkSignMD5(SortedDictionary <string, string> sParaTemp, String md5_key)
        {
            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);

            sign_src += "&key=" + md5_key;
            try
            {
                if (sign.Equals(Md5Algorithm.getInstance().md5Digest(
                                    Encoding.UTF8.GetBytes(sign_src))))
                {
                    Console.WriteLine("商户[" + oid_partner
                                      + "]MD5签名验证通过");
                    return(true);
                }
                else
                {
                    Console.WriteLine("商户[" + oid_partner
                                      + "]MD5签名验证未通过");
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("商户[" + oid_partner
                                  + "]MD5签名验证异常" + e.Message);
                return(false);
            }
        }