Beispiel #1
0
        public static void Main(string[] args)
        {
            var myClass = new MyClass()
            {
                MyProperty1 = 1,
                Name        = "1",
                Parent      = new MyClass()
                {
                    Name = "mc"
                }
            };
            var path = myClass.Path();

            Console.WriteLine(path);

            myClass.SetProperty(nameof(MyClass.MyProperty1), 1);
            Console.ReadKey();
            var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048);

            Console.WriteLine(rsaKey.PrivateKey);
            Console.WriteLine(rsaKey.PublicKey);
            var enc = "123456".RSAEncrypt();

            Console.WriteLine(enc);
            Console.Beep();
            var dec = enc.RSADecrypt();

            Console.WriteLine(dec);
            Console.ReadKey();
            //CreateWebHostBuilder(args).Build().Run();
        }
        /// <summary>
        /// 登录页
        /// </summary>
        /// <returns></returns>
        public ActionResult Login()
        {
            var keys = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS1);

            Response.Cookies.Append(nameof(keys.PublicKey), keys.PublicKey, new CookieOptions()
            {
                SameSite = SameSiteMode.Lax
            });
            HttpContext.Session.Set(nameof(keys.PrivateKey), keys.PrivateKey);
            string from = Request.Query["from"];

            if (!string.IsNullOrEmpty(from))
            {
                from = HttpUtility.UrlDecode(from);
                Response.Cookies.Append("refer", from, new CookieOptions()
                {
                    SameSite = SameSiteMode.Lax
                });
            }

            if (HttpContext.Session.Get <UserInfoDto>(SessionKey.UserInfo) != null)
            {
                if (string.IsNullOrEmpty(from))
                {
                    return(RedirectToAction("Index", "Home"));
                }

                return(LocalRedirect(from));
            }

            if (Request.Cookies.Count > 2)
            {
                string name     = Request.Cookies["username"];
                string pwd      = Request.Cookies["password"]?.DesDecrypt(AppConfig.BaiduAK);
                var    userInfo = UserInfoService.Login(name, pwd);
                if (userInfo != null)
                {
                    Response.Cookies.Append("username", name, new CookieOptions()
                    {
                        Expires  = DateTime.Now.AddYears(1),
                        SameSite = SameSiteMode.Lax
                    });
                    Response.Cookies.Append("password", Request.Cookies["password"], new CookieOptions()
                    {
                        Expires  = DateTime.Now.AddYears(1),
                        SameSite = SameSiteMode.Lax
                    });
                    HttpContext.Session.Set(SessionKey.UserInfo, userInfo);
                    HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.LoginRecord), "default", userInfo, ClientIP, LoginType.Default);
                    if (string.IsNullOrEmpty(from))
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                    return(LocalRedirect(from));
                }
            }

            return(View());
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            RsaKey keys = RsaCrypt.GenerateRsaKeys();

            Console.WriteLine(keys.PublicKey);
            Console.WriteLine(keys.PrivateKey);
        }
Beispiel #4
0
        public async Task <IActionResult> Rsa(string str)
        {
            var rsaKey = RsaCrypt.GenerateRsaKeys();
            var enc    = str.RSAEncrypt();
            var dec    = enc.RSADecrypt();

            return(Ok(dec));
        }
Beispiel #5
0
        public static void Main(string[] args)
        {
            var cpa = new ComplexPasswordAttribute(6, 30)
            {
                MustNumber = false,
                MustSymbol = true,
                MustLetter = false
            };
            var valid = cpa.IsValid("000000a");

            Console.WriteLine(cpa.ErrorMessage);


            Console.ReadKey();
            var myClass = new MyClass()
            {
                MyProperty1 = 1,
                Id          = "mcc",
                Pid         = "mc",
                Parent      = new MyClass()
                {
                    Id     = "mc",
                    Pid    = "ccc",
                    Parent = new MyClass()
                    {
                        Id = "ccc"
                    }
                }
            };
            var allParent = myClass.AllParent().Append(myClass);
            var tree      = allParent.ToTreeGeneral(c => c.Id, c => c.Pid);

            Console.WriteLine(tree.ToJsonString(new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                Formatting            = Formatting.Indented
            }));
            var path = myClass.Path(c => c.Id);

            Console.WriteLine(path);

            myClass.SetProperty(nameof(MyClass.MyProperty1), 1);
            Console.ReadKey();
            var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048);

            Console.WriteLine(rsaKey.PrivateKey);
            Console.WriteLine(rsaKey.PublicKey);
            var enc = "123456".RSAEncrypt();

            Console.WriteLine(enc);
            Console.Beep();
            var dec = enc.RSADecrypt();

            Console.WriteLine(dec);
            Console.ReadKey();
            //CreateWebHostBuilder(args).Build().Run();
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            var rsaKey = RsaCrypt.GenerateRsaKeys();
            var enc    = "123456".RSAEncrypt();
            var dec    = enc.RSADecrypt();

            Console.WriteLine(dec);
            Console.ReadKey();
            //CreateWebHostBuilder(args).Build().Run();
        }
Beispiel #7
0
        public static void Main(string[] args)
        {
            Enumerable.Range(1, 2).Select(i => new
            {
                序号 = i,
                图片 = new Dictionary <string, FileStream>()
                {
                    ["https://ldqk.org/1383"] = File.OpenRead(@"D:\images\emotion\16.jpg")
                }
            }).ToDataTable("aa").ToExcel().SaveFile(@"Y:\2.xlsx");
            var myClass = new MyClass()
            {
                MyProperty1 = 1,
                Id          = "mcc",
                Pid         = "mc",
                Parent      = new MyClass()
                {
                    Id     = "mc",
                    Pid    = "ccc",
                    Parent = new MyClass()
                    {
                        Id = "ccc"
                    }
                }
            };
            var allParent = myClass.AllParent().Append(myClass);
            var tree      = allParent.ToTreeGeneral(c => c.Id, c => c.Pid);

            Console.WriteLine(tree.ToJsonString(new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                Formatting            = Formatting.Indented
            }));
            var path = myClass.Path(c => c.Id);

            Console.WriteLine(path);

            myClass.SetProperty(nameof(MyClass.MyProperty1), 1);
            Console.ReadKey();
            var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048);

            Console.WriteLine(rsaKey.PrivateKey);
            Console.WriteLine(rsaKey.PublicKey);
            var enc = "123456".RSAEncrypt();

            Console.WriteLine(enc);
            Console.Beep();
            var dec = enc.RSADecrypt();

            Console.WriteLine(dec);
            Console.ReadKey();
            //CreateWebHostBuilder(args).Build().Run();
        }
        public void RsaCryptWordTestWithNoException()
        {
            var rsaKey = RsaCrypt.GenerateRsaKeys();

            string result = new RsaCryptTestEntity()
            {
                SdTime = DateTime.Parse("2020-08-14"),
                Name   = "asdf"
            }
            .ToJsonExt()
            .RSAEncrypt()
            .RSADecrypt();

            Assert.Equal(result, "123");
        }
Beispiel #9
0
        public static void Main(string[] args)
        {
            var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048);

            Console.WriteLine(rsaKey.PrivateKey);
            Console.WriteLine(rsaKey.PublicKey);
            var enc = "123456".RSAEncrypt();

            Console.WriteLine(enc);
            Console.Beep();
            var dec = enc.RSADecrypt();

            Console.WriteLine(dec);
            Console.ReadKey();
            //CreateWebHostBuilder(args).Build().Run();
        }
Beispiel #10
0
        public static void Main(string[] args)
        {
            var myClass = new MyClass()
            {
                MyProperty1 = 1,
                Id          = "mcc",
                Pid         = "mc",
                Parent      = new MyClass()
                {
                    Id     = "mc",
                    Pid    = "ccc",
                    Parent = new MyClass()
                    {
                        Id = "ccc"
                    }
                }
            };
            var allParent = myClass.AllParent().Append(myClass);
            var tree      = allParent.ToTreeGeneral(c => c.Id, c => c.Pid);

            tree.Flatten(t => t.Children).Select(t => t.Value).ToDataTable().ToExcel().SaveFile(@"Y:\1.xlsx");
            Console.WriteLine(tree.ToJsonString(new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                Formatting            = Formatting.Indented
            }));
            var path = myClass.Path(c => c.Id);

            Console.WriteLine(path);

            myClass.SetProperty(nameof(MyClass.MyProperty1), 1);
            Console.ReadKey();
            var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048);

            Console.WriteLine(rsaKey.PrivateKey);
            Console.WriteLine(rsaKey.PublicKey);
            var enc = "123456".RSAEncrypt();

            Console.WriteLine(enc);
            Console.Beep();
            var dec = enc.RSADecrypt();

            Console.WriteLine(dec);
            Console.ReadKey();
            //CreateWebHostBuilder(args).Build().Run();
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            var rsaKey = RsaCrypt.GenerateRsaKeys(512);

            Console.WriteLine(rsaKey.PrivateKey);
            var enc = new MyClass()
            {
                SdTime     = DateTime.Now,
                MyProperty = "asdf"
            }.ToJsonString().RSAEncrypt();

            Console.WriteLine(enc);
            Console.WriteLine(HiPerfTimer.Execute(() =>
            {
                var dec = enc.RSADecrypt();
                Console.WriteLine(dec);
            }) * 1000);
        }
Beispiel #12
0
        public static void Main(string[] args)
        {
            var list = new List <string>();

            list.AddRangeIfNotContains("1", "11"); // 将被添加元素中的长度大于1的元素添加到list
            var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048);

            Console.WriteLine(rsaKey.PrivateKey);
            Console.WriteLine(rsaKey.PublicKey);
            var enc = "123456".RSAEncrypt();

            Console.WriteLine(enc);
            Console.Beep();
            var dec = enc.RSADecrypt();

            Console.WriteLine(dec);
            Console.ReadKey();
            //CreateWebHostBuilder(args).Build().Run();
        }
Beispiel #13
0
        public static void Main(string[] args)
        {
            var fs    = File.OpenRead(@"E:\下载\BlazorSamples.7z");
            var bytes = fs.ToArrayAsync().Result;

            Console.WriteLine(bytes.Length);
            Console.ReadKey();
            var myClass = new MyClass()
            {
                MyProperty1 = 1,
                Name        = "1",
                Parent      = new MyClass()
                {
                    Name = "mc"
                }
            };
            var path = myClass.Path();

            Console.WriteLine(path);

            myClass.SetProperty(nameof(MyClass.MyProperty1), 1);
            Console.ReadKey();
            var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048);

            Console.WriteLine(rsaKey.PrivateKey);
            Console.WriteLine(rsaKey.PublicKey);
            var enc = "123456".RSAEncrypt();

            Console.WriteLine(enc);
            Console.Beep();
            var dec = enc.RSADecrypt();

            Console.WriteLine(dec);
            Console.ReadKey();
            //CreateWebHostBuilder(args).Build().Run();
        }
Beispiel #14
0
        private RsaKey GetRsaKey()
        {
            RsaKey rsaKey = RsaCrypt.GenerateRsaKeys();// 生成RSA密钥对

            return(rsaKey);
        }
Beispiel #15
0
 /// <summary>
 /// 生成rsa秘钥
 /// </summary>
 /// <param name="rsaKeyType">密钥类型</param>
 /// <param name="length">密钥长度</param>
 /// <returns></returns>
 public RsaKey GenerateRsaKeys(RsaKeyType rsaKeyType = RsaKeyType.XML, int length = 1024)
 {
     return(RsaCrypt.GenerateRsaKeys(rsaKeyType, length));
 }