示例#1
0
        private void PrivateKeyDncrypt_Click(object sender, EventArgs e)
        {
            String body = textBox_Body.Text.Trim(), privateKey = textBox_PrivateKey.Text.Trim();

            if (String.IsNullOrEmpty(body))
            {
                MessageBox.Show("待处理文本不能为空", "温馨提示");
                return;
            }
            if (String.IsNullOrEmpty(privateKey))
            {
                MessageBox.Show("私钥不能为空", "温馨提示");
                return;
            }

            //textBox_CryptBody.Text = RSACrypto.Decrypt(body, privateKey, false);
            try
            {
                textBox_CryptBody.Text = RSACrypto.Decrypt(body, privateKey, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误");
                logSaveProvider.SaveLog(LogProvider.Factories.LogEntityFactory.Create(ex));
            }
        }
示例#2
0
        public JsonResult Validate()
        {
            #region 公钥 私钥
            //-----BEGIN PUBLIC KEY-----
            //MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC4mZ8DLLwSMETsoQTKdu4efwhd
            //fTY/rxhsGA5EittII0/SeDQlRC4IzpxzMTKQSMWvnRlvD7V4Z2u1KBGhE++i/T5K
            //RdNCBXdo/G0pUdP2Nf4DpMP30HF54GwP8iZoXWVLy/tWtdZx9DUvajCn6GmgnjqK
            //NPTiCQsARLvYAou18wIDAQAB
            //-----END PUBLIC KEY-----

            //-----BEGIN RSA PRIVATE KEY-----
            //MIICXAIBAAKBgQC4mZ8DLLwSMETsoQTKdu4efwhdfTY/rxhsGA5EittII0/SeDQl
            //RC4IzpxzMTKQSMWvnRlvD7V4Z2u1KBGhE++i/T5KRdNCBXdo/G0pUdP2Nf4DpMP3
            //0HF54GwP8iZoXWVLy/tWtdZx9DUvajCn6GmgnjqKNPTiCQsARLvYAou18wIDAQAB
            //AoGAHjwbDTwQebIqN8+Pp1GfYqNPzXAqqHeXOm0eOR+9Fq2h70j80XW/THX6retK
            //6tLgfgjvF3+tK1FVFNDBQm6veuzRQjUO5JE0uRs4LSlRECa0ENxPgxFtELtTzRdJ
            //u/KXY3DB+ke+RLG0azylcwGeCtNbijYEneCqpCK5Fpjh8yECQQC/YWl4VCbqAUKE
            //GBipUdg9C8l/Aq/0H1vnS9jepvi5lYmSMNY60/r9h89qNbTB5FOn6LZC0n/TDmFL
            //YSr1MTiZAkEA9u4e5i2lJUG4w5IQGRKDrAzmto9a0ooQatPKoW4XiEHmwnZWFTUD
            //3eUc0IDlh+WYGi41Bg1+dzn9h0blq+Q+awJAR5Lo3QWr4AxEkh5o6rofQwVrgELD
            //B2vK9T/ahbqwfse8QZ5eIHYzAiqOmcwoI/N+jedscqVDBO312Tkn1bdo0QJBAOQC
            //HpAGh96uIBCeN7UfDmx5ATSDjKaqC9zIset7/8i2qYDYykYMzQRBAelZjBh/HYLX
            //Nejf3u3yozMdeQfO2v8CQD/uSS5BeJerr4pnF4suTzaqpIW66D2HVI3JxssBJWwt
            //fdVFi1a6EbZc0mHTzY/zLVX/ApTXbQZSFF/rwG0P8Dk=
            //-----END RSA PRIVATE KEY-----
            #endregion

            string publicKey  = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC4mZ8DLLwSMETsoQTKdu4efwhdfTY/rxhsGA5EittII0/SeDQlRC4IzpxzMTKQSMWvnRlvD7V4Z2u1KBGhE++i/T5KRdNCBXdo/G0pUdP2Nf4DpMP30HF54GwP8iZoXWVLy/tWtdZx9DUvajCn6GmgnjqKNPTiCQsARLvYAou18wIDAQAB";
            string privateKey = @"MIICXAIBAAKBgQC4mZ8DLLwSMETsoQTKdu4efwhdfTY/rxhsGA5EittII0/SeDQlRC4IzpxzMTKQSMWvnRlvD7V4Z2u1KBGhE++i/T5KRdNCBXdo/G0pUdP2Nf4DpMP30HF54GwP8iZoXWVLy/tWtdZx9DUvajCn6GmgnjqKNPTiCQsARLvYAou18wIDAQABAoGAHjwbDTwQebIqN8+Pp1GfYqNPzXAqqHeXOm0eOR+9Fq2h70j80XW/THX6retK6tLgfgjvF3+tK1FVFNDBQm6veuzRQjUO5JE0uRs4LSlRECa0ENxPgxFtELtTzRdJu/KXY3DB+ke+RLG0azylcwGeCtNbijYEneCqpCK5Fpjh8yECQQC/YWl4VCbqAUKEGBipUdg9C8l/Aq/0H1vnS9jepvi5lYmSMNY60/r9h89qNbTB5FOn6LZC0n/TDmFLYSr1MTiZAkEA9u4e5i2lJUG4w5IQGRKDrAzmto9a0ooQatPKoW4XiEHmwnZWFTUD3eUc0IDlh+WYGi41Bg1+dzn9h0blq+Q+awJAR5Lo3QWr4AxEkh5o6rofQwVrgELDB2vK9T/ahbqwfse8QZ5eIHYzAiqOmcwoI/N+jedscqVDBO312Tkn1bdo0QJBAOQCHpAGh96uIBCeN7UfDmx5ATSDjKaqC9zIset7/8i2qYDYykYMzQRBAelZjBh/HYLXNejf3u3yozMdeQfO2v8CQD/uSS5BeJerr4pnF4suTzaqpIW66D2HVI3JxssBJWwtfdVFi1a6EbZc0mHTzY/zLVX/ApTXbQZSFF/rwG0P8Dk=";

            RSACrypto rsaCrypto = new RSACrypto(privateKey, publicKey);
            //获取参数
            string usernameEncode = Request["username"];
            string pwdEncode      = Request["passwd"];

            string name1 = CommonHelper.GetPostValue("username", 100, true, true, true);
            string pwd2  = CommonHelper.GetPostValue("passwd", 100, true, true, true);

            //解密 RSA
            string username = rsaCrypto.Decrypt(usernameEncode);
            string pwd      = rsaCrypto.Decrypt(pwdEncode);

            string username3 = rsaCrypto.Decrypt(name1);
            string pwd3      = rsaCrypto.Decrypt(pwd2);
            return(null);
        }
示例#3
0
        private static BigInteger decryptDiffieHellmanKeys(string cKeyRsa, RSACrypto rsa)
        {
            byte[]     cKeyRsaBytes = Converter.HexStringToBytes(cKeyRsa);
            byte[]     cKeyBytes    = rsa.Decrypt(cKeyRsaBytes, true);
            BigInteger key          = convertBytesToKey(cKeyBytes);

            return(key);
        }
示例#4
0
        public string GetJieMiData(string guid, string mStr)
        {
            RSACrypto crypto = new RSACrypto();
            var       item   = RedisHelper.Get <RSAItem>(guid);

            RedisHelper.Remove(guid);
            return(crypto.Decrypt(item.PrivateKey, mStr));
        }
示例#5
0
        public void WhenIDecyptWordShouldBeEqual()
        {
            var word = "teste";

            var encryptedResult = rsaCrypto.Encrypt(word);
            var decryptedWord   = rsaCrypto.Decrypt(encryptedResult);

            Assert.AreEqual(word, decryptedWord);
        }
示例#6
0
        public bool Validate(License license)
        {
            var specText  = JsonConvert.SerializeObject(license.Specification);
            var hash      = Hash.KnuthHash(specText);
            var etx       = Convert.FromBase64String(license.AuthorizationCode);
            var ptx       = _crypto.Decrypt(etx, false, true);
            var decrypted = BitConverter.ToUInt64(ptx, 0);

            return(hash == decrypted);
        }
 private void dec_btn_rsa_Click(object sender, EventArgs e)
 {
     if (check_file_rsa == true)
     {
         dec_message_rsa.Text = rsa.Decrypt_File(message_rsa.Text);
     }
     else
     {
         dec_message_rsa.Text = rsa.Decrypt();
     }
 }
示例#8
0
        static void Main(string[] args)
        {
            string plaintext = "abc"; string strmd5 = "900150983CD24FB0D6963F7D28E17F72"; string strdes = "Wr+MOY7jM8M=";

            //MD5
            var s1 = MD5Crypto.Encrypt(plaintext);

            Console.WriteLine("MD5 加密:{0} {1} {2}", s1 == strmd5, strmd5, s1); Console.WriteLine();

            //DES
            var s2 = DESCrypto.Encrypt(plaintext);

            Console.WriteLine("DES 加密:{0} {1} {2}", s2 == strdes, strdes, s2);

            var s3 = DESCrypto.Decrypt(s2);

            Console.WriteLine("DES 解密:{0} {1} {2}", s3 == plaintext, plaintext, s3); Console.WriteLine();

            //RSA
            string modulus = "nJDcBWNIV+DzZb8ZY5h4JJInVwVy5NvJ9hG0qH0TUM36j5DUFeUivBIdX+7fxwKIxPRkRyvwVjGjnMxna3Kq53Y5BLGpl84DvRqPGjxly2kAitbuHRIR5iiuza0rbA+ZPo/8kNrbRCYquaqnL1KIrDcIh7bZDWN6qY22+RVaVvs=";

            string publicExponent  = "AQAB";
            string privateExponent = "ZZTTPCerc2D/ar9vYKA3KzssjRh68CPuSFo6hasJEj9iVy2XfVE6lR2Hs4uP41YwmOEcAtVuTO5OAljYrO0sFpdYNrEthZG5UBkC2wH+SsXOAaTDb2YRCEsdxFA8MRqRQLux/9/Fef/oIk+od1sjC3WzBwMqvVHBO232u9V9suE=";

            //公钥加密
            var s4 = RSACrypto.EncryptByPublicExponent(plaintext, modulus, publicExponent);

            Console.WriteLine("RSA 公钥加密:" + s4);

            string p        = "y8v6G7Ap6jeTHILLAjQT0auvd9kRh91txQ4YkGf8ocijRbThKgAtWUrvNx27km6PEetWqw0VnA2YN53v6WCBMQ==";
            string q        = "xKuz+9vgOYZf9WvA0vU8byCmZd93mYrw+uAymUiT6jvG1MQ0vAQMW7wwoifJYIqWFNZo356R6g2OeOz8Edfv6w==";
            string dp       = "vqI3et721ljWC71tGMqOH3txz7IFbAn9PG9LGwmqj8uWrwXb+eXghb5KtkvhwcAZpLF3iNncdPViheP/H1degQ==";
            string dq       = "dZ+ruYo7hKwVYBbd8E2zo1MHsg4A3df3YFQObxa1QHYX6NCgKYLSUVswSws4qYC5WiUR/Aw+gJkzCKfT6mgXmQ==";
            string inverseQ = "Fohpu2QfkHBCy11L0MV88pX3+EszJWWSgXqsGUzxTx0c2WK33o5wZkjq0AEKgk19aOOJc0RoKwcw6vtRRux/+Q==";
            //私钥解密
            var s5  = RSACrypto.DecryptByPrivateExponent(s4, modulus, privateExponent, publicExponent, p, q, dp, dq, inverseQ);
            var s55 = RSACrypto.Decrypt(s4, modulus, privateExponent);

            Console.WriteLine("RSA 私钥解密 : {0} {1} {2}", s5 == plaintext, plaintext, s5);
            Console.WriteLine("RSA 私钥解密2: {0} {1} {2}", s55 == plaintext, plaintext, s55); Console.WriteLine();

            //私钥加密
            var s6 = RSACrypto.Encrypt(plaintext, modulus, privateExponent);

            Console.WriteLine("RSA 私钥加密:" + s6);

            //公钥解密
            var str6 = RSACrypto.Decrypt(s6, modulus, publicExponent);

            Console.WriteLine("RSA 公钥解密2:{0} {1} {2}", str6 == plaintext, plaintext, str6);

            Console.ReadKey();
        }
示例#9
0
        private string CommonLogin(HttpContext context)
        {
            RSACrypto rsaCrypto = new RSACrypto(ConstValue.AES_KEY_PRIVATE, ConstValue.AES_KEY_PUBLIC);
            var       username  = rsaCrypto.Decrypt(context.Request["username"]);
            var       password  = rsaCrypto.Decrypt(context.Request["password"]);

            var login_result = sso_facade.DoLogin(username, password);

            //登录成功

            if (login_result.IsSucess)
            {
                var cookie = new HttpCookie(ConstValue.COOKIE_KEY_CURRENT_LOGIN_USER, username);
                cookie.Expires = DateTime.Now.AddMinutes(60 * 8);
                HttpContext.Current.Response.Cookies.Add(cookie);
                var ret_model = login_result.Datas as DZAFCPortal.ViewModel.Client.SSOModel.LoginResult_VM;
                //FormsAuthentication..SetAuthCookie(username, false);
                HttpContext.Current.Session.Add($"{ConstValue.SSO.APPLICATION_AUTH_PREFIX_URL}{username}", ret_model.applicationAuths);
            }

            return(JsonConvert.SerializeObject(login_result));
        }
示例#10
0
        private string CommonLoginBeta(HttpContext context)
        {
            RSACrypto rsaCrypto = new RSACrypto(ConstValue.AES_KEY_PRIVATE, ConstValue.AES_KEY_PUBLIC);
            var       username  = rsaCrypto.Decrypt(context.Request["username"]);
            var       password  = rsaCrypto.Decrypt(context.Request["password"]);

            var model = sso_facade.DoLoginBeta(username, password);

            //登录成功
            if (model.errorNumber == 0 && model.errors.Count == 0)
            {
                var cookie = new HttpCookie(ConstValue.COOKIE_KEY_CURRENT_LOGIN_USER, username);
                cookie.Expires = DateTime.Now.AddMinutes(60 * 8);
                HttpContext.Current.Response.Cookies.Add(cookie);
                //FormsAuthentication..SetAuthCookie(username, false);
                HttpContext.Current.Session.Add($"{ConstValue.SSO.APPLICATION_AUTH_PREFIX_URL}{username}", model.applicationAuths);

                return(JsonConvert.SerializeObject(new { IsSucess = true }));
            }
            else
            {
                return(JsonConvert.SerializeObject(new { IsSucess = false, Message = $"[{model.errorNumber}]{string.Join(";", model.errors)}" }));
            }
        }
示例#11
0
        public void Test()
        {
            using (var rsaCrypto = new RSACrypto())
            {
                rsaCrypto.Initialize(new Dictionary <string, object>
                {
                    { "Algorithm", "RSA" },
                    { "PublicKey", "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD2KXcCt30MrOOt4F1vhtfNViBGapFRmxaOnSVK9FMPV63Pr8Y3EzFpLFH58TzbNtwoB5aWRy4zjImbwsy5S2eqmSkJQWbWZiyxMLEYy1+dQDr27SihLp7BvrDUj8uy+LIO6fwCDMKJ2sQtXh+Uk6AO9meqdpA5riUEDVQKbpw6IQIDAQAB" },
                    { "PrivateKey", "MIICXQIBAAKBgQD2KXcCt30MrOOt4F1vhtfNViBGapFRmxaOnSVK9FMPV63Pr8Y3EzFpLFH58TzbNtwoB5aWRy4zjImbwsy5S2eqmSkJQWbWZiyxMLEYy1+dQDr27SihLp7BvrDUj8uy+LIO6fwCDMKJ2sQtXh+Uk6AO9meqdpA5riUEDVQKbpw6IQIDAQABAoGBAL0EW+kPIgtgmjdCaByiKwT11DSd0dYawzhg/GjQsRK/3avzKb3SlAdRS+UjUvp05poqMXxVTemxSVz8OJ0zhHYePa+wE0E31sBfnMxpOo5LIraTQuKGhE5IXNgUB0xYyAkG4vLLmoGDFCUHWPHYw5591C66eNyhJMSkPcqSCbMNAkEA+8HXhp3Ut1LVqBFnSpUIoRkUfXotWvfJjat6GGtmyglSRqTcUkVwIlBabVEMDyoMS9/LQcXM2QQ3bJiTKpDY3wJBAPpPe8Tfjm2o1Oxz8aGjnt+u2b4SZ9WXXkbZY1qsMNAkrP7ZFF5MTIm9L18V+yrvZ0mU7YC5Mck+F5eEbIxOTP8CQQDf0X1i2H58XNBGEvLZg5WgY0OsKiqYbSJrKL/rZdCEXbUfyQF2wvTmDLnX5e3qrV8xNUzmtIthhDYh/aMYfJ3RAkAMy39SIvNO27B2nb6eOpTmbjOnKZ2xJ1mkWXxgqCiemyFUrZgC8fd/mvIO9DqwiShIdJpnWBAZb1kZX6WEzoPVAkAz0CHiCH5JGdf71zCifbfFfcXA9+IXqQxvU9+3yGLAQW1S7xd94f8uOX+CsWsUchOpwmgzXYpvMLEtu822WqfF" }
                });
                var plainText = "SmartSql";

                var cipherText  = rsaCrypto.Encrypt(plainText);
                var decryptText = rsaCrypto.Decrypt(cipherText);
                Assert.Equal(plainText, decryptText);
            }
        }
示例#12
0
        public ActionResult Encrypt(string passwd)
        {
            string PrivateKey = @"-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCZoXqoJktTWSTolirHAFpLdK3w1eaawiKu9q7VQeqghF7S90IJ
FKlawmuLhiEmrOLOqG0AYQOSdX0WSEcRlGH/VKwz5XNOsLutQWSfG2xt4bXT+nAm
qp/nWpeSlNuFYhsCWSjFydAtoUjLBXi0gusaBDpwfgq4zBGXAA7M3uVmTwIDAQAB
AoGBAIZ0khHJ+hDHKws4KdYik+QICReHTRzSnWI9WUQhPYQgdZDzf2LNJ27cSx1A
VZEwrAur0kILpgGvO7udpD1ZfO2Lg3lcBN+CVjp97oJPFCYQdD1yuRRjpvCsrLLu
zzfuSNatYbgS8lCh6HloSB7XThck8W6GbmNJsiYscn6GztUJAkEAvCeDzQKjZxvc
1+VS+dPzOAq8nBVuQES9V5PZM0tHfNuA1J04l0Y4c9mMWsh6YOBsTz46vs5yuCKk
Ptwg6pLlNQJBANEHGdCZJOgKWUg6Xraz38RBM1cPHKzYEmOu1HiNl30wGCuM1b61
8xsDntaHXYHJxYgiudVwzH5Sj2iRVn2CIfMCQALAGR8gEL9rGtlVEtdwD7gcABHQ
BmKOHq5vDNfBG/RpSQLSoYckkaKv5WtWTuOnpC2sXTN41Rh3+SqqERkcuJkCQAFW
HUkjIYRGRKncjax3W+/iRtTAqPtF6mAuxvb6WMSZIR5uKROuEB7VGBfhB60DwDqN
lkiSDwyjtH0DqNzmjxcCQQCvIhCkietd1YSG1Jl7zSmuT3NksNwj4HGYSfMLdkBV
ag8pleWkHqBf9Z1d/qbOkealNgmmiE8JO/vGuM7T0uDw
-----END RSA PRIVATE KEY-----
";


            string PublicKey = @"-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZoXqoJktTWSTolirHAFpLdK3w
1eaawiKu9q7VQeqghF7S90IJFKlawmuLhiEmrOLOqG0AYQOSdX0WSEcRlGH/VKwz
5XNOsLutQWSfG2xt4bXT+nAmqp/nWpeSlNuFYhsCWSjFydAtoUjLBXi0gusaBDpw
fgq4zBGXAA7M3uVmTwIDAQAB
-----END PUBLIC KEY-----";


            PrivateKey = PrivateKey.Replace("-----BEGIN RSA PRIVATE KEY-----", "")
                         .Replace("-----END RSA PRIVATE KEY-----", "");

            PublicKey = PublicKey.Replace("-----BEGIN PUBLIC KEY-----", "")
                        .Replace("-----END PUBLIC KEY-----", "");
            RSACrypto rsaCrypto = new RSACrypto(PrivateKey, PublicKey);



            //解密 RSA

            string pwd = rsaCrypto.Decrypt(passwd);

            return(Json(pwd));
        }
示例#13
0
        public ActionResult Upload(HttpPostedFileBase arquivo)
        {
            try
            {
                var content = "";

                if (arquivo.ContentLength > 0)
                {
                    var file = new Facensa.SegurancaApp.Core.Infra.File(System.Web.HttpContext.Current);

                    var encryptedFileContent = "";
                    using (var sr = new StreamReader(arquivo.InputStream))
                    {
                        encryptedFileContent = sr.ReadToEnd();
                    }

                    var fileLines = encryptedFileContent.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var l in fileLines)
                    {
                        var list = new List <uint>();
                        var a    = l.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                        foreach (var c in a)
                        {
                            list.Add((uint)int.Parse(c));
                        }

                        content += _rsaCrypto.Decrypt(list) + "\r\n";
                    }
                }

                ViewBag.content = content;

                return(View("Index"));
            }
            catch (Exception)
            {
                ViewBag.Erro = "Esta chave é inválida";
                return(View("Index"));
            }
        }
示例#14
0
        public void EncryptDecryptTests()
        {
            // Arrange
            var sectionText = $@"{{
                ""RSA"": {{
                    ""PublicKey"": ""{publicKey}"",
                    ""PrivateKey"": ""{privateKey}""
                }}
            }}";

            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(sectionText));
            var section = new ConfigurationBuilder().AddJsonStream(stream).Build().GetSection("RSA");

            var crypto = new RSACrypto(section);

            var input = "Hello, Etsoo";

            // Act
            var result        = crypto.Encrypt(input);
            var decryptResult = Encoding.UTF8.GetString(crypto.Decrypt(result));

            // Assert
            Assert.AreEqual(input, decryptResult);
        }
示例#15
0
 public static CryptedUserInfo GetDecrypted(string encrypted)
 {
     return(JsonConvert.DeserializeObject <CryptedUserInfo>(RSACrypto.Decrypt(encrypted)));
 }
示例#16
0
        public string Decrypt(string key, string data)
        {
            var rsa = new RSACrypto(key);

            return(rsa.Decrypt(data));
        }
示例#17
0
        public async Task <ActionResult> Process(string request, string extension, int errCount, string token)
        {
            LogCall(request, extension);

            TwilioData twilioConfig = await TwilioConfigDataProvider.GetConfigCondAsync();

            if (twilioConfig == null || !twilioConfig.IsConfigured())
            {
                return(RejectResult("Twilio is not configured"));
            }
            string    authToken = twilioConfig.TestMode ? twilioConfig.TestAuthToken : twilioConfig.LiveAuthToken;
            IVRConfig ivrConfig = await IVRConfigDataProvider.GetConfigCondAsync();

            if (ivrConfig == null || string.IsNullOrWhiteSpace(ivrConfig.PublicKey) || string.IsNullOrWhiteSpace(ivrConfig.PrivateKey))
            {
                return(RejectResult("Config settings not available"));
            }

#if !DEBUG
            // There is something very peculiar about twilio verification. The initial request will validate correctly, but anything after that will not.
            // Even if the only difference is CallStatus (tested with a redirect to Request=Main. So I gave up and validate just the first one
            // and add my own token validation (as argument)
            if (string.IsNullOrWhiteSpace(token))
            {
                if (!Verify.VerifyTwilio(authToken, twilioConfig.TestMode ? ivrConfig.TestVerificationProcessCallUrl : ivrConfig.LiveVerificationProcessCallUrl))
                {
                    return(RejectResult("Twilio verification failed"));
                }
            }
            else
            {
                // verify token. If it wasn't generated within the last 5 minutes, reject it.
                string decryptedToken;
                RSACrypto.Decrypt(ivrConfig.PrivateKey, token, out decryptedToken);
                DateTime tokenTime = new DateTime(Convert.ToInt64(decryptedToken));
                if (tokenTime < DateTime.UtcNow.AddMinutes(-5))
                {
                    return(RejectResult("Token verification failed"));
                }
            }
#endif
            if (string.IsNullOrWhiteSpace(request))
            {
                // call log

                using (CallLogDataProvider callLogDP = new CallLogDataProvider()) {
                    await callLogDP.AddItemAsync(new CallLogEntry {
                        Caller        = GetForm("From")?.Truncate(Globals.MaxPhoneNumber),
                        CallerCity    = GetForm("CallerCity")?.Truncate(CallLogEntry.MaxCity),
                        CallerCountry = GetForm("CallerCountry")?.Truncate(CallLogEntry.MaxCountry),
                        CallerState   = GetForm("CallerState")?.Truncate(CallLogEntry.MaxState),
                        CallerZip     = GetForm("CallerZip")?.Truncate(CallLogEntry.MaxZip),
                        To            = GetForm("Called")?.Truncate(Globals.MaxPhoneNumber),
                    });
                }

                // check for blocked numbers
                using (BlockedNumberDataProvider blockedDP = new BlockedNumberDataProvider()) {
                    BlockedNumberEntry blockedEntry = await blockedDP.GetItemAsync(GetForm("From"));

                    if (blockedEntry != null)
                    {
                        return(RejectResult($"Blocked number {GetForm("From")}"));
                    }
                }

                // notify (new call)
                foreach (ExtensionPhoneNumber notifyNumber in ivrConfig.NotificationNumbers)
                {
                    if (notifyNumber.SendSMS)
                    {
                        SendSMS sendSMS = new SendSMS();
                        await sendSMS.SendMessageAsync(notifyNumber.PhoneNumber,
                                                       this.__ResStr("notifySMS", "Incoming call received from {0} ({1}, {2}, {3}, {4}) - {5}",
                                                                     GetForm("Caller"), GetForm("CallerCity"), GetForm("CallerState"), GetForm("CallerZip"), GetForm("CallerCountry"), GetForm("To")),
                                                       ThrowError : false);
                    }
                }

                // determine main action to run

                request = SECTION_MAIN;
                using (HolidayEntryDataProvider holidayDP = new HolidayEntryDataProvider()) {
                    HolidayEntry holiday = await holidayDP.GetItemAsync(DateTime.Now.Date.ToUniversalTime());

                    if (holiday != null)
                    {
                        request = SECTION_MAINHOLIDAY;
                    }
                    else if (ivrConfig.OpeningHours.IsClosed(DateTime.UtcNow))
                    {
                        request = SECTION_MAINCLOSED;
                    }
                }
            }

            string called;
            if (!TryGetForm("CalledVia", out called))
            {
                called = GetForm("Called");
            }

            if (ivrConfig.MaxErrors != 0 && errCount >= ivrConfig.MaxErrors)
            {
                request = SECTION_MAINGOODBYE;
            }

            request = request.ToLower();

            using (ScriptDataProvider scriptDP = new ScriptDataProvider()) {
                ScriptData script = await scriptDP.GetScriptAsync(called);

                if (script == null)
                {
                    return(RejectResult($"Script not found for {called}"));
                }

                // See if a valid extension was entered
                if (request == SECTION_GATHEREXTENSION.ToLower())
                {
                    string digits;
                    if (TryGetForm("Digits", out digits))
                    {
                        Extension ext = script.FindExtension(digits);
                        if (ext != null)
                        {
                            extension = ext.Digits;
                            request   = SECTION_ENTEREDEXTENSION.ToLower(); // a valid extension was entered, run EnteredExtension instead
                        }
                    }
                }

                // find the entry that matches the name and parameters
                List <ScriptEntry> entries = (from e in script.Scripts where e.Tag == request select e).ToList();
                foreach (ScriptEntry entry in entries)
                {
                    if (entry.Parms.Count > 0)
                    {
                        // check parms
                        bool valid = true;
                        foreach (ScriptParm parm in entry.Parms)
                        {
                            if (GetForm(parm.Name) != parm.Value)
                            {
                                valid = false;
                                break;
                            }
                        }
                        if (!valid)
                        {
                            continue;
                        }
                    }
                    return(await RunEntryAsync(ivrConfig, script, called, extension, entry, errCount));
                }
                throw new InternalError($"Nothing to execute - tag \"{request}\" for {called}");
            }
        }
示例#18
0
文件: Program.cs 项目: lylbin/NH.Core
        static void Main(string[] args)
        {
            var mm = HttpCommon.HttpPost("http://api.1cloudsp.com/intl/api/v2/send", "accesskey=as5xjYLRv6ehVZL7&secret=GwxOKj0WOOon4NAJi52s0I4GnZqlGZ2u&sign=【IDCM】&templateId=999&mobile=8615019400599&content=27672");

            string param = "json=kfPL3B20IkN2F7W85/3qrJjUfphS83IZp9VwT3no/AxLfwG46DUu3+cmzxgyGxoUmjpnKtmbzkdsDLQrIiISJGRpv2L4oJRhcpXjYKbeopqhNJ16Mnk0qH2Z2Y3LvSJAPi/4tgcjNY52uED7etWgAoeOWKlR1VBq88eJBH0wlr/nGesDHH2lMl4VAu99xE8CKwnfsI2R+BJxTdZzQIAjQjGWeTvNqArcXN+VBD/9o16x9OTpMXqNg7itaWZ1ddWbC4nIdO9KoXv7vd02dhNwY2ovAzUorNj+J5xnLfVZZqp44jxcLw2a7AGZ3TMlfinTU76mbm4+n/rhMpdryWTwyw==";

            HttpCommon.HttpPost("http://preapi.idcm.io:8303/api/ExternalAPI/SignIn", param);


            //2048 公钥
            string publicKey =
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwnsbSgsVdgscvfHpcwIE+3/Ny5swzVlUpJMveQDmdNool++SESap8r9Vhsc1lvO8W3omj6KAQ0j6as8ZTSGS3ngp0uf7nTgnuVxLfCF8UNhtOkbWomGZWoobM8LM+RX0VzzbPsVB7q0gmUPkH4M2TcPV2cjDyl2t3Om0ZDh0qaQjtTCUrc6BmCfYoAZpBoMIlM8gUViBi9TxxW2HvKlreUkM/IOyikRRmkIm/rkhqHO4z5HQoZzz0+QkxoqFMmkV5YZaoM0DQ7957vMNZUOxvmjg17GjJHVJzF/Keo25bEYdvnTVnjmAc+EMc+6qjrFIVuhE+T5l3rfE+4jqdzkN+QIDAQAB";



            //2048 私钥
            string privateKey =
                "MIIEogIBAAKCAQEAwnsbSgsVdgscvfHpcwIE+3/Ny5swzVlUpJMveQDmdNool++SESap8r9Vhsc1lvO8W3omj6KAQ0j6as8ZTSGS3ngp0uf7nTgnuVxLfCF8UNhtOkbWomGZWoobM8LM+RX0VzzbPsVB7q0gmUPkH4M2TcPV2cjDyl2t3Om0ZDh0qaQjtTCUrc6BmCfYoAZpBoMIlM8gUViBi9TxxW2HvKlreUkM/IOyikRRmkIm/rkhqHO4z5HQoZzz0+QkxoqFMmkV5YZaoM0DQ7957vMNZUOxvmjg17GjJHVJzF/Keo25bEYdvnTVnjmAc+EMc+6qjrFIVuhE+T5l3rfE+4jqdzkN+QIDAQABAoIBAHUJwRJ+ORwg89sbinI79OOltiOh8WyjJd0k9pzLfeU0pNlKw4yux/feTYoeuJFvfRtQF4S5NpdHg+xjVcalPc3EYucZ1MJ42O8kLAk33aiJlrJLjz+JnNBv7I7p3JDKNZGKfib4bwVECyoxQUf1nuiNwlSeDbXrSoZ33qexkgPER1zm2TUUi/17Wo62p1/J5l8SoxebaATzme0YWdP6rdbGIQ3ujYsgBxql+txWgNgiy0Yfduv/msdzL4X4oiZZa1XV8ivW8KyNs4XiUm5rIehQFmlYf1an/1qhHQvQXM+k0Bh8v5VJ8LflxkYddLdVnW+dPjT9FRegI4mrfjfgTkECgYEA41h2bwWFIn6CbeF+4eJxpdZENt5GKDDjCQB0jMj2Lx4hrE2cfOEybORAsE8RL2nLGKiTII2+bMqvHY1Sover5C/NraKCXyHPTji27eubTbPUWFfgIB/EvucXs/MqTn9W1xtZZGdDq1Ioxy87/0f9ervwSo1IKEZYQNkYNnEhulsCgYEA2v47TUCNE8r7Je12qf526jcpljIsNgrm6HQOObQcvVVP7wpmqvPcSlCPMEIUzbJupygRS/3p6E0kDgS4FzOaFKK1MlSI+eSsxN+H4eKQ6uzdcmvIG8sAyFww+4v5iNXeWXPFMOp2Qsog95y96zgYgrFU8Q91ZXHPMMetnUIGQTsCgYBlSW5KfD0aZx6Y8dPjs01KwzFU+KZtFYqw4gELECWOTHBYIaPMh1A971tasX9Ijmurqr8Ry9TBB3QJSIM+k/WDDkEmULagx6FiiiYFzeg9MBc03MG/zieLnc2ToIyCuHzqDQdAkjk1xL7iLwsd6ublnYGq1VMGjoCXM6Fz7+dE7QKBgEPnKrokdtoZSVCUVgQV7AdpvVJeEklbjger3LFVwMeQSW3EWttNLBQ68Hs1MkApwJfCG8LlY37tVG2oVvCSxob5gJevkJ1zo4KUEQ0gdHDzqyKMewrrIj3+IA4Pc/tS3VP9SrqFKNBC3oAIsPbbePYlSEJK2crvxB/K+nFVhJz7AoGAFx/SJsinfHcuvSrgSQdNbORmJbqnYULh2LDKp/z15D29Anya3Qzq/pHdTb8wOC7FM388pMy9eyNaga50GzfhhAiqm5CnKoMRjFWwTUVe33w+JA2an/ZHObeb/DyRuf8KrPJT7QuLCveQg5RA4mXNeBW1dBS0ebUqn1vOs8R8+X0=";



            //1024 私钥
            string publicKey2 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCA++n8NNERrGNAq9w+sKYCW/2gc5yfBDvfwf1W6P1zA4VANyQr9Kr3WmJRi6TUFfrHpOKNApJRNgcKegxJAvxAih1v6z2KGS/OFaojBr+/06MbZ/vVNpQrMr00z5wRFI1hQ8C8o7xRmMuDQtfHr5DAM5nF7tIUNjD2N2AT2c3FwIDAQAB";

            string privateKey2 = "MIICXAIBAAKBgQDCA++n8NNERrGNAq9w+sKYCW/2gc5yfBDvfwf1W6P1zA4VANyQr9Kr3WmJRi6TUFfrHpOKNApJRNgcKegxJAvxAih1v6z2KGS/OFaojBr+/06MbZ/vVNpQrMr00z5wRFI1hQ8C8o7xRmMuDQtfHr5DAM5nF7tIUNjD2N2AT2c3FwIDAQABAoGAcVd3VDb+VO6vnt8ouunjcIpi3DFs97i+9ArUDWRh3qA8wcxlDimI+1o34zga0XioQ/Ty4FQShkcvsRRSTxLt3fM61VSq0Aa8/8vtgzGHS8tnLc3kNJniJuhP6EDHowyEC7lsOxiwH6dr2GNH4Yts0x/Xz9GzZB9KV4wIY57tjtECQQDsYFoIeevJxmeoxUHfdtePKiZTnkVG1Qu01+m/b+PKu0bJLEtdgDvMYxeaB+potHRDLNKxWBUWfWPN9XE3kG2NAkEA0h9L9Jt+HcCgfbujlOMviZWloTUzXlWAmIb/rc+6CS6RWoRQOrN5y7aCskr7lTERL9gQTeuNgTewuDiv8tP0MwJAcE3C2N4cQYxrOYsmpeYPuiw7c2Tx4xpbanteyh596pcZpYDO+chwIMY/s2XpX//EcRn9rFZ+BmZiobroJI8RDQJBAJIfwaqyF9qJAxNtUi1QcNa1gyHA5aBMxclM2LH/K9kG0X6pVUH9Xk4U9n8XNi5imRk0oOIPVbDvEa6LfZDZZZECQF/BcEVRB7txuIryMUQTHoguAn9yIdmiyEAdfujlFcEo7b9vyh3grr29vAC95jy4fjXNBPSgffE76MTGNmCykvE=";



            var rsa = new RSAHelper(RSAType.RSA, Encoding.UTF8, privateKey, publicKey);

            var test = new RSACrypto(privateKey, publicKey);


            string str = "123456";

            Console.WriteLine("原始字符串:" + str);

            //加密
            string enStr = rsa.Encrypt(str);

            enStr = "NR4tG5D/sRriuNoonT5AqRMNetmpcnndgQ8Rr8c3AJbkBwSSejlYl7Xraqi4UDiYZfAxLMf2sPpwT9IJmTGBO+xRpaHN0BumgRE1w+5quB7wae6zagIE5DC+M8dkC+kuBSPD8FLn7Vgo8r84vFGTsYKpUt7JvpoqkypU1nEsN4akv/mpGXCQOFqN9EWKggq3uniDXiZ5Wg35ls4AqmPSY5A/XMf84WKNR6xcBt+rUz/Z8lRn7mEBphhyEmHr0tDs3sY23hGnU9kKmV9rjcqh4rgQ+N7SnY+koJYHd32pOTdmrcXYRuWv4szk86wWp+GTj1wZ2bLe5j44idfWSuQkPw==";
            //enStr = "NR4tG5D/sRriuNoonT5AqRMNetmpcnndgQ8Rr8c3AJbkBwSSejlYl7Xraqi4UDiYZfAxLMf2sPpwT9IJmTGBO xRpaHN0BumgRE1w 5quB7wae6zagIE5DC M8dkC kuBSPD8FLn7Vgo8r84vFGTsYKpUt7JvpoqkypU1nEsN4akv/mpGXCQOFqN9EWKggq3uniDXiZ5Wg35ls4AqmPSY5A/XMf84WKNR6xcBt rUz/Z8lRn7mEBphhyEmHr0tDs3sY23hGnU9kKmV9rjcqh4rgQ N7SnY koJYHd32pOTdmrcXYRuWv4szk86wWp GTj1wZ2bLe5j44idfWSuQkPw==";
            string enStr2 = test.Encrypt(str);
            string enStr3 = "t3N885z0IL9aASYjcJppftNoF5eoDfVyuJsxcQSRc3C+/otctMs8azKgPo12zHERr/3AOLoVXNk4GQX2o36ksqhf2BbrDFphVqEBbC/sh175XLXVSKcXP2Tb4EoE1B4QtzoRymV1nlTGERDrzeJ5vZUTEJStVpgNpp2UoDp3CIT4ASoIGhbnVieRLtDS/EukdYz2GKRAoygf9UBlzZkooit6Grb7JeF0zxcfY4X5EO4oehylvNDYTJcP9yfPF9NybW05DMpoNMNYHgDamYbKRwcv9SWIhZ6kY59NO4FO4Gv6/PYsNaLE6hMY4LE+0ITL0X8QAFhrG3j3fCWOw076mQ==";

            Console.WriteLine("A生成的加密字符串a:" + enStr);
            Console.WriteLine("B生成的加密字符串b:" + enStr2);
            Console.WriteLine("JS生成的加密字符串js:" + enStr3);
            //解密



            string deStr  = rsa.Decrypt(enStr);
            string deStr2 = rsa.Decrypt(enStr2);
            string deStr3 = rsa.Decrypt(enStr3);

            Console.WriteLine("A解密字符串a:" + deStr);
            Console.WriteLine("A解密字符串b:" + deStr2);
            Console.WriteLine("A解密字符js:" + deStr3);


            string deStr4 = test.Decrypt(enStr);
            string deStr5 = test.Decrypt(enStr2);
            string deStr6 = test.Decrypt(enStr3);

            Console.WriteLine("B解密字符串a:" + deStr4);
            Console.WriteLine("B解密字符串b:" + deStr5);
            Console.WriteLine("B解密字符js:" + deStr6);

            Console.ReadKey();
        }