private static byte[] decrypt(byte[] data, string privateKey, string input_charset) { RSACryptoServiceProvider rSACryptoServiceProvider = RSAFromPkcs8.DecodePemPrivateKey(privateKey); SHA1 sHA = new SHA1CryptoServiceProvider(); return(rSACryptoServiceProvider.Decrypt(data, false)); }
private static RSACryptoServiceProvider DecodePemPrivateKey(string pemstr) { byte[] array = Convert.FromBase64String(pemstr); if (array != null) { return(RSAFromPkcs8.DecodePrivateKeyInfo(array)); } return(null); }
public static string sign(string content, string privateKey, string input_charset) { Encoding encoding = Encoding.GetEncoding(input_charset); byte[] bytes = encoding.GetBytes(content); RSACryptoServiceProvider rSACryptoServiceProvider = RSAFromPkcs8.DecodePemPrivateKey(privateKey); SHA1 halg = new SHA1CryptoServiceProvider(); byte[] inArray = rSACryptoServiceProvider.SignData(bytes, halg); return(Convert.ToBase64String(inArray)); }
public static bool verify(string content, string signedString, string publicKey, string input_charset) { bool flag = false; Encoding encoding = Encoding.GetEncoding(input_charset); byte[] bytes = encoding.GetBytes(content); byte[] signature = Convert.FromBase64String(signedString); RSAParameters parameters = RSAFromPkcs8.ConvertFromPublicKey(publicKey); RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider(); rSACryptoServiceProvider.ImportParameters(parameters); SHA1 halg = new SHA1CryptoServiceProvider(); return(rSACryptoServiceProvider.VerifyData(bytes, halg, signature)); }
private bool GetSignVeryfy(SortedDictionary <string, string> inputPara, string sign) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary = Core.FilterPara(inputPara); string content = Core.CreateLinkString(dictionary); bool result = false; if (sign != null && sign != "") { string sign_type = this._sign_type; if (sign_type == "RSA") { result = RSAFromPkcs8.verify(content, sign, this._public_key, this._input_charset); } } return(result); }
public static string decryptData(string resData, string privateKey, string input_charset) { byte[] array = Convert.FromBase64String(resData); List <byte> list = new 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[Encoding.GetEncoding(input_charset).GetCharCount(array3, 0, array3.Length)]; Encoding.GetEncoding(input_charset).GetChars(array3, 0, array3.Length, array4, 0); return(new string(array4)); }
protected void Page_Load(object sender, EventArgs e) { OrderInfo orderInfo = null; decimal num = default(decimal); string text = base.Request.QueryString.Get("orderId"); int num2 = base.Request.QueryString.Get("isrecharge").ToInt(0); string value; if (!string.IsNullOrEmpty(text)) { value = text; if (num2 == 1) { InpourRequestInfo inpourBlance = MemberProcessor.GetInpourBlance(text); if (inpourBlance != null) { num = inpourBlance.InpourBlance; goto IL_0183; } } else { orderInfo = OrderHelper.GetOrderInfo(text); if (orderInfo != null) { this.isFightGroup = ((orderInfo.FightGroupId > 0) ? "true" : "false"); if (orderInfo.PreSaleId > 0) { if (!orderInfo.DepositDate.HasValue && orderInfo.OrderStatus == OrderStatus.WaitBuyerPay) { num = ((orderInfo.Deposit - orderInfo.BalanceAmount > decimal.Zero) ? (orderInfo.Deposit - orderInfo.BalanceAmount) : decimal.Zero); } else if (orderInfo.DepositDate.HasValue && orderInfo.OrderStatus == OrderStatus.WaitBuyerPay) { num = orderInfo.FinalPayment; } } else { num = orderInfo.GetTotal(true); } value = text + new Random().Next(10000, 99999).ToString(); goto IL_0183; } } } return; IL_0183: try { PaymentModeInfo paymentMode = SalesHelper.GetPaymentMode("hishop.plugins.payment.ws_apppay.wswappayrequest"); string xml = HiCryptographer.Decrypt(paymentMode.Settings); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.XmlResolver = null; xmlDocument.LoadXml(xml); XmlNodeList elementsByTagName = xmlDocument.GetElementsByTagName("Partner"); XmlNodeList elementsByTagName2 = xmlDocument.GetElementsByTagName("Seller_account_name"); XmlNodeList elementsByTagName3 = xmlDocument.GetElementsByTagName("Key"); if (elementsByTagName == null || elementsByTagName2 == null || elementsByTagName3 == null) { this.pay_json = "config_error"; } else { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("partner=\""); stringBuilder.Append(xmlDocument.GetElementsByTagName("Partner")[0].InnerText); stringBuilder.Append("\"&out_trade_no=\""); stringBuilder.Append(value); stringBuilder.Append("\"&subject=\""); stringBuilder.Append((num2 == 1) ? "预付款充值" : "订单支付"); stringBuilder.Append("\"&body=\""); stringBuilder.Append("订单号-").Append(text); stringBuilder.Append("\"&total_fee=\""); stringBuilder.Append(num.F2ToString("f2")); stringBuilder.Append("\"¬ify_url=\""); stringBuilder.Append(Globals.UrlEncode(Globals.FullPath("/pay/app_alipay_notify_url"))); 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\""; } } catch (Exception) { this.pay_json = "config_error"; } }
private static RSACryptoServiceProvider DecodePrivateKeyInfo(byte[] pkcs8) { byte[] b = new byte[15] { 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0 }; byte[] array = new byte[15]; MemoryStream memoryStream = new MemoryStream(pkcs8); int num = (int)memoryStream.Length; BinaryReader binaryReader = new BinaryReader(memoryStream); byte b2 = 0; ushort num2 = 0; try { switch (binaryReader.ReadUInt16()) { case 33072: binaryReader.ReadByte(); break; case 33328: binaryReader.ReadInt16(); break; default: return(null); } b2 = binaryReader.ReadByte(); if (b2 != 2) { return(null); } num2 = binaryReader.ReadUInt16(); if (num2 != 1) { return(null); } array = binaryReader.ReadBytes(15); if (!RSAFromPkcs8.CompareBytearrays(array, b)) { return(null); } b2 = binaryReader.ReadByte(); if (b2 != 4) { return(null); } switch (binaryReader.ReadByte()) { case 129: binaryReader.ReadByte(); break; case 130: binaryReader.ReadUInt16(); break; } byte[] privkey = binaryReader.ReadBytes((int)(num - memoryStream.Position)); return(RSAFromPkcs8.DecodeRSAPrivateKey(privkey)); } catch (Exception) { return(null); } finally { binaryReader.Close(); } }
private static RSACryptoServiceProvider DecodeRSAPrivateKey(byte[] privkey) { MemoryStream input = new MemoryStream(privkey); BinaryReader binaryReader = new BinaryReader(input); byte b = 0; ushort num = 0; int num2 = 0; try { switch (binaryReader.ReadUInt16()) { case 33072: binaryReader.ReadByte(); break; case 33328: binaryReader.ReadInt16(); break; default: return(null); } num = binaryReader.ReadUInt16(); if (num != 258) { return(null); } if (binaryReader.ReadByte() != 0) { return(null); } num2 = RSAFromPkcs8.GetIntegerSize(binaryReader); byte[] modulus = binaryReader.ReadBytes(num2); num2 = RSAFromPkcs8.GetIntegerSize(binaryReader); byte[] exponent = binaryReader.ReadBytes(num2); num2 = RSAFromPkcs8.GetIntegerSize(binaryReader); byte[] d = binaryReader.ReadBytes(num2); num2 = RSAFromPkcs8.GetIntegerSize(binaryReader); byte[] p = binaryReader.ReadBytes(num2); num2 = RSAFromPkcs8.GetIntegerSize(binaryReader); byte[] q = binaryReader.ReadBytes(num2); num2 = RSAFromPkcs8.GetIntegerSize(binaryReader); byte[] dP = binaryReader.ReadBytes(num2); num2 = RSAFromPkcs8.GetIntegerSize(binaryReader); byte[] dQ = binaryReader.ReadBytes(num2); num2 = RSAFromPkcs8.GetIntegerSize(binaryReader); byte[] inverseQ = binaryReader.ReadBytes(num2); RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider(); RSAParameters parameters = default(RSAParameters); parameters.Modulus = modulus; parameters.Exponent = exponent; parameters.D = d; parameters.P = p; parameters.Q = q; parameters.DP = dP; parameters.DQ = dQ; parameters.InverseQ = inverseQ; rSACryptoServiceProvider.ImportParameters(parameters); return(rSACryptoServiceProvider); } catch (Exception) { return(null); } finally { binaryReader.Close(); } }