Ejemplo n.º 1
0
        static void TestStringCrypto()
        {
            string P = "thisisaplaintext";
            string K = "thisisakey";

            Console.WriteLine("P: " + P);
            Console.WriteLine("K: " + K);
            Console.WriteLine();
            // Ayni string'i ayni anahtar ile 20 kere sifrele
            // Hepsinin sifrelenmis hali farklı ama cozunce ayni string degerini veriyor
            for (int i = 0; i < 20; i++)
            {
                string C1 = P.Encrypt(K);
                string P1 = C1.Decrypt(K);
                Console.WriteLine("C{0}: " + C1, i + 1);
                Console.WriteLine("P{0}: " + P1, i + 1);
                Console.WriteLine();
            }

            // Empty string icin test
            string CBos = StringCrypto.Encrypt(string.Empty, string.Empty);
            string PBos = StringCrypto.Decrypt(CBos, string.Empty);

            Console.WriteLine("CBos: " + CBos);
            Console.WriteLine("PBos: " + PBos);
            Console.WriteLine();

            Console.WriteLine("Internal Test: " + StringCrypto.Test().ToString());
        }
Ejemplo n.º 2
0
        public void BaseTest()
        {
            var cy     = new StringCrypto(Convert.ToBase64String("123".ToArrayInByte()), Convert.ToBase64String("321".ToArrayInByte()));
            var 加密后字符串 = cy.Encrypt("abc");

            Console.WriteLine(加密后字符串);

            var 解密字符串 = cy.Decrypt(加密后字符串);

            Assert.AreEqual("abc", 解密字符串);
        }
Ejemplo n.º 3
0
        public void EncryptTest()
        {
            string       strBase64KEY = string.Empty;                                // TODO: 初始化为适当的值
            string       strBase64IV  = string.Empty;                                // TODO: 初始化为适当的值
            StringCrypto target       = new StringCrypto(strBase64KEY, strBase64IV); // TODO: 初始化为适当的值
            string       strValue     = string.Empty;                                // TODO: 初始化为适当的值
            string       expected     = string.Empty;                                // TODO: 初始化为适当的值
            string       actual;

            actual = target.Encrypt(strValue);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Index(QueryViewModel model)
        {
            if (!model.HasIntent)
            {
                var luisService = new LuisService(new LuisModelAttribute(ConfigurationManager.AppSettings["LuisApplicationId"], ConfigurationManager.AppSettings["LuisSubscriptionKey"]));
                var luisResult  = await luisService.QueryAsync(model.Query, CancellationToken.None);

                var resolver = new LuisActionResolver(typeof(GetTimeInPlaceAction).Assembly);
                var action   = resolver.ResolveActionFromLuisIntent(luisResult);

                // Triggering Contextual Action from scratch is not supported on this Web Sample
                if (action != null && !LuisActionResolver.IsContextualAction(action))
                {
                    model.LuisAction = action;

                    // Store the Action name, encrypted
                    model.LuisActionType = StringCrypto.Encrypt(action.GetType().AssemblyQualifiedName);
                }
                else
                {
                    // no action recognized
                    return(this.View(new QueryViewModel()));
                }
            }

            ModelState.Clear();
            var isValid = TryValidateModel(model.LuisAction);

            if (isValid)
            {
                // fulfill
                var actionResult = await model.LuisAction.FulfillAsync();

                if (actionResult == null)
                {
                    actionResult = "Cannot resolve your query";
                }

                return(this.View("ActionFulfill", actionResult));
            }
            else
            {
                // not valid, continue to present form with missing/invalid parameters
                return(this.View(model));
            }
        }