示例#1
0
 private static System.Security.Cryptography.RSACryptoServiceProvider DecodePemPrivateKey(string pemstr)
 {
     byte[] array = System.Convert.FromBase64String(pemstr);
     if (array != null)
     {
         return(RSAFromPkcs8.DecodePrivateKeyInfo(array));
     }
     return(null);
 }
示例#2
0
 public static bool verify(string content, string signedString, string publicKey, string input_charset)
 {
     System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(input_charset);
     byte[] bytes     = encoding.GetBytes(content);
     byte[] signature = System.Convert.FromBase64String(signedString);
     System.Security.Cryptography.RSAParameters            parameters = RSAFromPkcs8.ConvertFromPublicKey(publicKey);
     System.Security.Cryptography.RSACryptoServiceProvider rSACryptoServiceProvider = new System.Security.Cryptography.RSACryptoServiceProvider();
     rSACryptoServiceProvider.ImportParameters(parameters);
     System.Security.Cryptography.SHA1 halg = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     return(rSACryptoServiceProvider.VerifyData(bytes, halg, signature));
 }
示例#3
0
        private bool GetSignVeryfy(System.Collections.Generic.SortedDictionary <string, string> inputPara, string sign)
        {
            System.Collections.Generic.Dictionary <string, string> dicArray = new System.Collections.Generic.Dictionary <string, string>();
            dicArray = Core.FilterPara(inputPara);
            string content = Core.CreateLinkString(dicArray);
            bool   result  = false;
            string sign_type;

            if (sign != null && sign != "" && (sign_type = this._sign_type) != null && sign_type == "RSA")
            {
                result = RSAFromPkcs8.verify(content, sign, this._public_key, this._input_charset);
            }
            return(result);
        }
示例#4
0
 public static string decryptData(string resData, string privateKey, string input_charset)
 {
     byte[] array = System.Convert.FromBase64String(resData);
     System.Collections.Generic.List <byte> list = new System.Collections.Generic.List <byte>();
     for (int i = 0; i < array.Length / 128; i++)
     {
         byte[] array2 = new byte[128];
         for (int j = 0; j < 128; j++)
         {
             array2[j] = array[j + 128 * i];
         }
         list.AddRange(RSAFromPkcs8.decrypt(array2, privateKey, input_charset));
     }
     byte[] array3 = list.ToArray();
     char[] array4 = new char[System.Text.Encoding.GetEncoding(input_charset).GetCharCount(array3, 0, array3.Length)];
     System.Text.Encoding.GetEncoding(input_charset).GetChars(array3, 0, array3.Length, array4, 0);
     return(new string(array4));
 }
示例#5
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            string text = base.Request.QueryString.Get("orderId");

            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            OrderInfo orderInfo = OrderHelper.GetOrderInfo(text);

            if (orderInfo == null)
            {
                return;
            }
            PaymentModeInfo paymentMode = SalesHelper.GetPaymentMode("Ecdev.plugins.payment.ws_apppay.wswappayrequest");
            string          xml         = HiCryptographer.Decrypt(paymentMode.Settings);

            System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
            xmlDocument.LoadXml(xml);
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
            stringBuilder.Append("partner=\"");
            stringBuilder.Append(xmlDocument.GetElementsByTagName("Partner")[0].InnerText);
            stringBuilder.Append("\"&out_trade_no=\"");
            stringBuilder.Append(orderInfo.OrderId);
            stringBuilder.Append("\"&subject=\"");
            stringBuilder.Append("订单支付");
            stringBuilder.Append("\"&body=\"");
            stringBuilder.Append("订单号-").Append(orderInfo.OrderId);
            stringBuilder.Append("\"&total_fee=\"");
            stringBuilder.Append(orderInfo.GetTotal().ToString("F2"));
            stringBuilder.Append("\"&notify_url=\"");
            stringBuilder.Append(Globals.UrlEncode(Globals.FullPath("/pay/app_alipay_notify_url.aspx")));
            stringBuilder.Append("\"&service=\"mobile.securitypay.pay");
            stringBuilder.Append("\"&_input_charset=\"UTF-8");
            stringBuilder.Append("\"&return_url=\"");
            stringBuilder.Append(Globals.UrlEncode("http://m.alipay.com"));
            stringBuilder.Append("\"&payment_type=\"1");
            stringBuilder.Append("\"&seller_id=\"");
            stringBuilder.Append(xmlDocument.GetElementsByTagName("Seller_account_name")[0].InnerText);
            stringBuilder.Append("\"&it_b_pay=\"1m\"");
            string str = Globals.UrlEncode(RSAFromPkcs8.sign(stringBuilder.ToString(), xmlDocument.GetElementsByTagName("Key")[0].InnerText, "utf-8"));

            this.pay_json = stringBuilder.ToString() + "&sign=\"" + str + "\"&sign_type=\"RSA\"";
        }
示例#6
0
 public static string sign(string content, string privateKey, string input_charset)
 {
     System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(input_charset);
     byte[] bytes = encoding.GetBytes(content);
     System.Security.Cryptography.RSACryptoServiceProvider rSACryptoServiceProvider = RSAFromPkcs8.DecodePemPrivateKey(privateKey);
     System.Security.Cryptography.SHA1 halg = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     byte[] inArray = rSACryptoServiceProvider.SignData(bytes, halg);
     return(System.Convert.ToBase64String(inArray));
 }
示例#7
0
        private static System.Security.Cryptography.RSACryptoServiceProvider DecodePrivateKeyInfo(byte[] pkcs8)
        {
            byte[] b = new byte[]
            {
                48,
                13,
                6,
                9,
                42,
                134,
                72,
                134,
                247,
                13,
                1,
                1,
                1,
                5,
                0
            };
            byte[] a = new byte[15];
            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(pkcs8);
            int num = (int)memoryStream.Length;

            System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(memoryStream);
            System.Security.Cryptography.RSACryptoServiceProvider result;
            try
            {
                ushort num2 = binaryReader.ReadUInt16();
                if (num2 == 33072)
                {
                    binaryReader.ReadByte();
                }
                else
                {
                    if (num2 != 33328)
                    {
                        result = null;
                        return(result);
                    }
                    binaryReader.ReadInt16();
                }
                byte b2 = binaryReader.ReadByte();
                if (b2 != 2)
                {
                    result = null;
                }
                else
                {
                    num2 = binaryReader.ReadUInt16();
                    if (num2 != 1)
                    {
                        result = null;
                    }
                    else
                    {
                        a = binaryReader.ReadBytes(15);
                        if (!RSAFromPkcs8.CompareBytearrays(a, b))
                        {
                            result = null;
                        }
                        else
                        {
                            b2 = binaryReader.ReadByte();
                            if (b2 != 4)
                            {
                                result = null;
                            }
                            else
                            {
                                b2 = binaryReader.ReadByte();
                                if (b2 == 129)
                                {
                                    binaryReader.ReadByte();
                                }
                                else
                                {
                                    if (b2 == 130)
                                    {
                                        binaryReader.ReadUInt16();
                                    }
                                }
                                byte[] privkey = binaryReader.ReadBytes((int)((long)num - memoryStream.Position));
                                System.Security.Cryptography.RSACryptoServiceProvider rSACryptoServiceProvider = RSAFromPkcs8.DecodeRSAPrivateKey(privkey);
                                result = rSACryptoServiceProvider;
                            }
                        }
                    }
                }
            }
            catch (System.Exception)
            {
                result = null;
            }
            finally
            {
                binaryReader.Close();
            }
            return(result);
        }
示例#8
0
 private static byte[] decrypt(byte[] data, string privateKey, string input_charset)
 {
     System.Security.Cryptography.RSACryptoServiceProvider rSACryptoServiceProvider = RSAFromPkcs8.DecodePemPrivateKey(privateKey);
     new System.Security.Cryptography.SHA1CryptoServiceProvider();
     return(rSACryptoServiceProvider.Decrypt(data, false));
 }
示例#9
0
 private static System.Security.Cryptography.RSACryptoServiceProvider DecodeRSAPrivateKey(byte[] privkey)
 {
     System.IO.MemoryStream input        = new System.IO.MemoryStream(privkey);
     System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(input);
     System.Security.Cryptography.RSACryptoServiceProvider result;
     try
     {
         ushort num = binaryReader.ReadUInt16();
         if (num == 33072)
         {
             binaryReader.ReadByte();
         }
         else
         {
             if (num != 33328)
             {
                 result = null;
                 return(result);
             }
             binaryReader.ReadInt16();
         }
         num = binaryReader.ReadUInt16();
         if (num != 258)
         {
             result = null;
         }
         else
         {
             byte b = binaryReader.ReadByte();
             if (b != 0)
             {
                 result = null;
             }
             else
             {
                 int    integerSize = RSAFromPkcs8.GetIntegerSize(binaryReader);
                 byte[] modulus     = binaryReader.ReadBytes(integerSize);
                 integerSize = RSAFromPkcs8.GetIntegerSize(binaryReader);
                 byte[] exponent = binaryReader.ReadBytes(integerSize);
                 integerSize = RSAFromPkcs8.GetIntegerSize(binaryReader);
                 byte[] d = binaryReader.ReadBytes(integerSize);
                 integerSize = RSAFromPkcs8.GetIntegerSize(binaryReader);
                 byte[] p = binaryReader.ReadBytes(integerSize);
                 integerSize = RSAFromPkcs8.GetIntegerSize(binaryReader);
                 byte[] q = binaryReader.ReadBytes(integerSize);
                 integerSize = RSAFromPkcs8.GetIntegerSize(binaryReader);
                 byte[] dP = binaryReader.ReadBytes(integerSize);
                 integerSize = RSAFromPkcs8.GetIntegerSize(binaryReader);
                 byte[] dQ = binaryReader.ReadBytes(integerSize);
                 integerSize = RSAFromPkcs8.GetIntegerSize(binaryReader);
                 byte[] inverseQ = binaryReader.ReadBytes(integerSize);
                 System.Security.Cryptography.RSACryptoServiceProvider rSACryptoServiceProvider = new System.Security.Cryptography.RSACryptoServiceProvider();
                 rSACryptoServiceProvider.ImportParameters(new System.Security.Cryptography.RSAParameters
                 {
                     Modulus  = modulus,
                     Exponent = exponent,
                     D        = d,
                     P        = p,
                     Q        = q,
                     DP       = dP,
                     DQ       = dQ,
                     InverseQ = inverseQ
                 });
                 result = rSACryptoServiceProvider;
             }
         }
     }
     catch (System.Exception)
     {
         result = null;
     }
     finally
     {
         binaryReader.Close();
     }
     return(result);
 }