private static string BuildRequestMysign(Dictionary <string, string> sPara) { string str; string str1 = Hidistro.ControlPanel.OutPay.App.Core.CreateLinkString(sPara); string mD5 = ""; string _signType = Hidistro.ControlPanel.OutPay.App.Core._sign_type; if (_signType != null) { if (_signType == "RSA") { mD5 = RSAFromPkcs8.sign(str1, Hidistro.ControlPanel.OutPay.App.Core._private_key, Hidistro.ControlPanel.OutPay.App.Core._input_charset); str = mD5; return(str); } else { if (_signType != "MD5") { mD5 = ""; str = mD5; return(str); } mD5 = Hidistro.ControlPanel.OutPay.App.Core.GetMD5(string.Concat(str1, Hidistro.ControlPanel.OutPay.App.Core._private_key), Hidistro.ControlPanel.OutPay.App.Core._input_charset); str = mD5; return(str); } } mD5 = ""; str = mD5; return(str); }
private bool GetSignVeryfy(SortedDictionary <string, string> inputPara, string sign, [Optional, DefaultParameterValue("")] string _private_key) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); string content = Core.CreateLinkString(Core.FilterPara(inputPara)); bool flag = false; if ((sign == null) || !(sign != "")) { return(flag); } string str2 = Core._sign_type; if (str2 == null) { return(flag); } if (!(str2 == "RSA")) { if (str2 != "MD5") { return(flag); } } else { return(RSAFromPkcs8.verify(content, sign, this._public_key, Core._input_charset)); } return(Core.GetMD5(content + Core._private_key, Core._input_charset) == sign); }
private bool GetSignVeryfy(SortedDictionary <string, string> inputPara, string sign, string _private_key = "") { Dictionary <string, string> dicArray = new Dictionary <string, string>(); dicArray = Core.FilterPara(inputPara); string text = Core.CreateLinkString(dicArray); bool result = false; if (sign != null && sign != "") { string sign_type = Core._sign_type; if (sign_type != null) { if (!(sign_type == "RSA")) { if (sign_type == "MD5") { result = (Core.GetMD5(text + Core._private_key, Core._input_charset) == sign); } } else { result = RSAFromPkcs8.verify(text, sign, this._public_key, Core._input_charset); } } } return(result); }
private static byte[] decrypt(byte[] data, string privateKey, string input_charset) { RSACryptoServiceProvider rSACryptoServiceProvider = RSAFromPkcs8.DecodePemPrivateKey(privateKey); SHA1 sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider(); return(rSACryptoServiceProvider.Decrypt(data, false)); }
public static string sign(string content, string privateKey, string input_charset) { byte[] bytes = Encoding.GetEncoding(input_charset).GetBytes(content); RSACryptoServiceProvider rSACryptoServiceProvider = RSAFromPkcs8.DecodePemPrivateKey(privateKey); SHA1 sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider(); return(Convert.ToBase64String(rSACryptoServiceProvider.SignData(bytes, sHA1CryptoServiceProvider))); }
public static bool verify(string content, string signedString, string publicKey, string input_charset) { byte[] bytes = Encoding.GetEncoding(input_charset).GetBytes(content); byte[] numArray = Convert.FromBase64String(signedString); RSAParameters rSAParameter = RSAFromPkcs8.ConvertFromPublicKey(publicKey); RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider(); rSACryptoServiceProvider.ImportParameters(rSAParameter); return(rSACryptoServiceProvider.VerifyData(bytes, new SHA1CryptoServiceProvider(), numArray)); }
public static bool verify(string content, string signedString, string publicKey, string input_charset) { 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 static string BuildRequestMysign(Dictionary <string, string> sPara) { string content = CreateLinkString(sPara); switch (_sign_type) { case "RSA": return(RSAFromPkcs8.sign(content, _private_key, _input_charset)); case "MD5": return(GetMD5(content + _private_key, _input_charset)); } return(""); }
private static RSACryptoServiceProvider DecodePemPrivateKey(string pemstr) { RSACryptoServiceProvider rSACryptoServiceProvider; byte[] numArray = Convert.FromBase64String(pemstr); if (numArray == null) { rSACryptoServiceProvider = null; } else { rSACryptoServiceProvider = RSAFromPkcs8.DecodePrivateKeyInfo(numArray); } return(rSACryptoServiceProvider); }
private static RSACryptoServiceProvider DecodePemPrivateKey(string pemstr) { byte[] array = Convert.FromBase64String(pemstr); RSACryptoServiceProvider result; if (array != null) { RSACryptoServiceProvider rSACryptoServiceProvider = RSAFromPkcs8.DecodePrivateKeyInfo(array); result = rSACryptoServiceProvider; } else { result = null; } 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)); }
public static string decryptData(string resData, string privateKey, string input_charset) { byte[] numArray = Convert.FromBase64String(resData); List <byte> nums = new List <byte>(); for (int i = 0; i < (int)numArray.Length / 128; i++) { byte[] numArray1 = new byte[128]; for (int j = 0; j < 128; j++) { numArray1[j] = numArray[j + 128 * i]; } nums.AddRange(RSAFromPkcs8.decrypt(numArray1, privateKey, input_charset)); } byte[] array = nums.ToArray(); char[] chrArray = new char[Encoding.GetEncoding(input_charset).GetCharCount(array, 0, (int)array.Length)]; Encoding.GetEncoding(input_charset).GetChars(array, 0, (int)array.Length, chrArray, 0); return(new string(chrArray)); }
private static string BuildRequestMysign(Dictionary <string, string> sPara) { string text = Core.CreateLinkString(sPara); string sign_type = Core._sign_type; string result; if (sign_type != null) { if (sign_type == "RSA") { result = RSAFromPkcs8.sign(text, Core._private_key, Core._input_charset); return(result); } if (sign_type == "MD5") { result = Core.GetMD5(text + Core._private_key, Core._input_charset); return(result); } } result = ""; return(result); }
private static RSACryptoServiceProvider DecodeRSAPrivateKey(byte[] privkey) { MemoryStream input = new MemoryStream(privkey); BinaryReader binaryReader = new BinaryReader(input); 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); RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider(); rSACryptoServiceProvider.ImportParameters(new RSAParameters { Modulus = modulus, Exponent = exponent, D = d, P = p, Q = q, DP = dP, DQ = dQ, InverseQ = inverseQ }); result = rSACryptoServiceProvider; } } } catch (Exception) { result = null; } finally { binaryReader.Close(); } return(result); }
private static 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]; MemoryStream memoryStream = new MemoryStream(pkcs8); int num = (int)memoryStream.Length; BinaryReader binaryReader = new BinaryReader(memoryStream); 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)); RSACryptoServiceProvider rSACryptoServiceProvider = RSAFromPkcs8.DecodeRSAPrivateKey(privkey); result = rSACryptoServiceProvider; } } } } } catch (Exception) { result = null; } finally { binaryReader.Close(); } return(result); }
private static RSACryptoServiceProvider DecodeRSAPrivateKey(byte[] privkey) { RSACryptoServiceProvider rSACryptoServiceProvider; BinaryReader binaryReader = new BinaryReader(new MemoryStream(privkey)); ushort num = 0; try { try { num = binaryReader.ReadUInt16(); if (num == 33072) { binaryReader.ReadByte(); } else if (num != 33328) { rSACryptoServiceProvider = null; return(rSACryptoServiceProvider); } else { binaryReader.ReadInt16(); } num = binaryReader.ReadUInt16(); if (num != 258) { rSACryptoServiceProvider = null; } else if (binaryReader.ReadByte() == 0) { byte[] numArray = binaryReader.ReadBytes(RSAFromPkcs8.GetIntegerSize(binaryReader)); byte[] numArray1 = binaryReader.ReadBytes(RSAFromPkcs8.GetIntegerSize(binaryReader)); byte[] numArray2 = binaryReader.ReadBytes(RSAFromPkcs8.GetIntegerSize(binaryReader)); byte[] numArray3 = binaryReader.ReadBytes(RSAFromPkcs8.GetIntegerSize(binaryReader)); byte[] numArray4 = binaryReader.ReadBytes(RSAFromPkcs8.GetIntegerSize(binaryReader)); byte[] numArray5 = binaryReader.ReadBytes(RSAFromPkcs8.GetIntegerSize(binaryReader)); byte[] numArray6 = binaryReader.ReadBytes(RSAFromPkcs8.GetIntegerSize(binaryReader)); byte[] numArray7 = binaryReader.ReadBytes(RSAFromPkcs8.GetIntegerSize(binaryReader)); RSACryptoServiceProvider rSACryptoServiceProvider1 = new RSACryptoServiceProvider(); RSAParameters rSAParameter = new RSAParameters() { Modulus = numArray, Exponent = numArray1, D = numArray2, P = numArray3, Q = numArray4, DP = numArray5, DQ = numArray6, InverseQ = numArray7 }; rSACryptoServiceProvider1.ImportParameters(rSAParameter); rSACryptoServiceProvider = rSACryptoServiceProvider1; } else { rSACryptoServiceProvider = null; } } catch (Exception exception) { rSACryptoServiceProvider = null; } } finally { binaryReader.Close(); } return(rSACryptoServiceProvider); }
private static RSACryptoServiceProvider DecodePrivateKeyInfo(byte[] pkcs8) { RSACryptoServiceProvider rSACryptoServiceProvider; byte[] numArray = new byte[] { 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0 }; byte[] numArray1 = new byte[15]; MemoryStream memoryStream = new MemoryStream(pkcs8); int length = (int)memoryStream.Length; BinaryReader binaryReader = new BinaryReader(memoryStream); byte num = 0; ushort num1 = 0; try { try { num1 = binaryReader.ReadUInt16(); if (num1 == 33072) { binaryReader.ReadByte(); } else if (num1 != 33328) { rSACryptoServiceProvider = null; return(rSACryptoServiceProvider); } else { binaryReader.ReadInt16(); } num = binaryReader.ReadByte(); if (num == 2) { num1 = binaryReader.ReadUInt16(); if (num1 != 1) { rSACryptoServiceProvider = null; } else if (RSAFromPkcs8.CompareBytearrays(binaryReader.ReadBytes(15), numArray)) { num = binaryReader.ReadByte(); if (num == 4) { num = binaryReader.ReadByte(); if (num == 129) { binaryReader.ReadByte(); } else if (num == 130) { binaryReader.ReadUInt16(); } byte[] numArray2 = binaryReader.ReadBytes((int)((long)length - memoryStream.Position)); rSACryptoServiceProvider = RSAFromPkcs8.DecodeRSAPrivateKey(numArray2); } else { rSACryptoServiceProvider = null; } } else { rSACryptoServiceProvider = null; } } else { rSACryptoServiceProvider = null; } } catch (Exception exception) { rSACryptoServiceProvider = null; } } finally { binaryReader.Close(); } return(rSACryptoServiceProvider); }