Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine(2 << 1);
            Console.WriteLine(RsaKeyGenerator.XmlKey(2048)[0]);
            Console.WriteLine(RsaKeyGenerator.Pkcs1Key(2048, true)[0]);
            Console.WriteLine(RsaKeyGenerator.Pkcs8Key(2048, true)[0]);


            Console.WriteLine("Key Convert:");
            var keyList    = RsaKeyGenerator.Pkcs1Key(512, false);
            var privateKey = keyList[0];
            var publicKey  = keyList[1];

            Console.WriteLine("public key pkcs1->xml:");
            Console.WriteLine(RsaKeyConvert.PublicKeyPemToXml(publicKey));

            var bigDataRsa = new RsaPkcs1Util(Encoding.UTF8, publicKey, privateKey, 2048);
            var data       = "响应式布局的概念是一个页面适配多个终端及不同分辨率。在针对特定屏幕宽度优化应用 UI 时,我们将此称为创建响应式设计。WPF设计之初响应式设计的概念并不流行,那时候大部分网页设计师都按着宽度960像素的标准设计。到了UWP诞生的时候响应式布局已经很流行了,所以UWP提供了很多响应式布局的技术,这篇文章简单总结了一些响应式布局常用的技术,更完整的内容请看文章最后给出的参考网站。所谓的传统,是指在响应式设计没流行前XAML就已经存在的应对不同分辨率的技术,毕竟桌面客户端常常也调整窗体的大小,有些人还同时使用两个不同分辨率的屏幕。以我的经验来说以下这些做法可以使UI有效应对分辨率改变不同的DPI设定、不同的本地化字符串长度都可能使整个页面布局乱掉。而且和网页不同,WPF窗体默认没有提供ScrollViewer,所以千万不能忘记。在桌面客户端合理使用以上技术可以避免客户投诉。但UWP主打跨平台,它需要更先进(或者说,更激进)的技术。微软的官方文档介绍了UWP中响应式设计常用的6个技术,包括重新定位、调整大小、重新排列、显示/隐藏、替换和重新构建,具体可见以下网站:UWP中部分控件已经实现了响应式行为, 最典型的就是NavigationView。可以使用 PaneDisplayMode 属性配置不同的导航样式或显示模式。默认情况下,PaneDisplayMode 设置为 Auto。在 Auto 模式下,导航视图会进行自适应,在窗口狭窄时为 LeftMinimal,接下来为 LeftCompact,随后在窗口变宽时为 Left。这种时候MVVM的优势就体现出来了,因为VIEW和VIEWMODEL解耦了,VIEW随便换,而且整个UI显示隐藏说不定比多个小模块独自改变性能更好。说到性能,UWP的很多场景都为已经死了多年的WindowsWobile考虑了性能,更不用说现在的桌面平台,所以做UWP不需要太过介意性能,尤其是已经在WPF上培养出小心翼翼的习惯的开发者,UWP的性能问题等真的出现了再说。除了使用显示隐藏,UWP还可以使用限定符名称指定CodeBehind对应的XAML文件,这有点像是自适应应用的话题。使用格式如下";
            var str        = bigDataRsa.EncryptBigData(data, RSAEncryptionPadding.Pkcs1);

            Console.WriteLine("Big Data Encrypt:");
            Console.WriteLine(str);
            Console.WriteLine("Big Data Decrypt:");
            Console.WriteLine(string.Join("", bigDataRsa.DecryptBigData(str, RSAEncryptionPadding.Pkcs1)));

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine(RsaKeyGenerator.XmlKey(2048)[0]);
            Console.WriteLine(RsaKeyGenerator.Pkcs1Key(2048, true)[0]);
            Console.WriteLine(RsaKeyGenerator.Pkcs8Key(2048, true)[0]);


            Console.WriteLine("Key Convert:");
            var keyList    = RsaKeyGenerator.Pkcs1Key(2048, false);
            var privateKey = keyList[0];
            var publicKey  = keyList[1];

            Console.WriteLine("public key pkcs1->xml:");
            Console.WriteLine(RsaKeyConvert.PublicKeyPemToXml(publicKey));

            var bigDataRsa = new RsaPkcs1Util(Encoding.UTF8, publicKey, privateKey, 2048);
            var str        = bigDataRsa.EncryptBigData("abcdefg", 3, "$", RSAEncryptionPadding.Pkcs1);

            Console.WriteLine("Big Data Encrypt:");
            Console.WriteLine(str);
            Console.WriteLine("Big Data Decrypt:");
            Console.WriteLine(string.Join("", bigDataRsa.DecryptBigData(str, "$", RSAEncryptionPadding.Pkcs1)));

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            string filePath = Environment.CurrentDirectory;

            if (args.Length != 0)
            {
                filePath = args[0];
            }
            var keyList    = RsaKeyGenerator.Pkcs1Key(2048, false);
            var privateKey = keyList[0];
            var publicKey  = keyList[1];

            Console.WriteLine("生成成功!编码UTF-8");
            Console.WriteLine("私钥:");
            Console.WriteLine(privateKey);
            Console.WriteLine("公钥:");
            Console.WriteLine(publicKey);
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            File.WriteAllText(Path.Combine(filePath, "私钥.txt"), privateKey, Encoding.UTF8);
            File.WriteAllText(Path.Combine(filePath, "公钥.txt"), publicKey, Encoding.UTF8);
            Console.WriteLine("按任意键退出");
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Pkcs1格式的RSA密钥
        /// </summary>
        /// <returns></returns>
        public static string CreatePkcs1Key()
        {
            var keyList    = RsaKeyGenerator.Pkcs1Key(2048, true);
            var privateKey = keyList[0];
            var publicKey  = keyList[1];

            return($"私钥:{privateKey}\n公钥:{publicKey}");
        }
Ejemplo n.º 5
0
        private int OnExecute(CommandLineApplication app)
        {
            if (app.Options.Count == 1 && app.Options[0].ShortName == "h")
            {
                app.ShowHelp();
            }

            try
            {
                bool          pemFormat  = bool.Parse(PemFormat);
                string        publicKey  = string.Empty;
                string        privateKey = string.Empty;
                List <string> keyList;

                switch (Format)
                {
                case "xml":
                    keyList    = RsaKeyGenerator.XmlKey(KeySize);
                    privateKey = keyList[0];
                    publicKey  = keyList[1];
                    break;

                case "pkcs1":
                    keyList    = RsaKeyGenerator.Pkcs1Key(KeySize, pemFormat);
                    privateKey = keyList[0];
                    publicKey  = keyList[1];
                    break;

                case "pkcs8":
                    keyList    = RsaKeyGenerator.Pkcs8Key(KeySize, pemFormat);
                    privateKey = keyList[0];
                    publicKey  = keyList[1];
                    break;
                }

                if (!Directory.Exists(Output))
                {
                    Directory.CreateDirectory(Output);
                }

                File.WriteAllText(Path.Combine(Output, "public.key"), publicKey);
                File.WriteAllText(Path.Combine(Output, "private.key"), privateKey);

                app.Out.WriteLine($"Process success.File saved in {Output}.");
            }
            catch (Exception e)
            {
                app.Out.WriteLine($"Process error.Detail message:{e.Message}");
                return(1);
            }

            return(0);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var keyList    = RsaKeyGenerator.XmlKey(2048);
            var privateKey = keyList[0];
            var publicKey  = keyList[1];

            Console.WriteLine(RsaKeyGenerator.XmlKey(2048)[0]);
            Console.WriteLine(RsaKeyGenerator.Pkcs1Key(2048, true)[0]);
            Console.WriteLine(RsaKeyGenerator.Pkcs8Key(2048, true)[0]);

            Console.ReadKey();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine(RsaKeyGenerator.XmlKey(2048)[0]);
            Console.WriteLine(RsaKeyGenerator.Pkcs1Key(2048, true)[0]);
            Console.WriteLine(RsaKeyGenerator.Pkcs8Key(2048, true)[0]);


            Console.WriteLine("Key Convert:");
            var keyList    = RsaKeyGenerator.Pkcs1Key(2048, false);
            var privateKey = keyList[0];
            var publicKey  = keyList[1];

            Console.WriteLine("public key pkcs1->xml:");
            Console.WriteLine(RsaKeyConvert.PublicKeyPemToXml(publicKey));

            Console.ReadKey();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            var keyList = RsaKeyGenerator.Pkcs1Key(2048, true);

            Console.WriteLine($"Public key:\n{keyList.PublicKey}\n\nPrivate key:\n{keyList.PrivateKey}");

            Console.Write("String for encrypt: ");
            var test_string      = Console.ReadLine();
            var rsa_encryptor    = new RsaPkcs1Util(Encoding.UTF8, keyList.PublicKey);
            var encrypted_string = rsa_encryptor.Encrypt(test_string, RSAEncryptionPadding.Pkcs1);

            Console.WriteLine($"\nEncrypted string:\n{encrypted_string}\n");

            var rsa_decryptor    = new RsaPkcs1Util(Encoding.UTF8, keyList.PublicKey, keyList.PrivateKey);
            var decrypted_string = rsa_decryptor.Decrypt(encrypted_string, RSAEncryptionPadding.Pkcs1);

            Console.WriteLine($"\nDecrypted string:\n{decrypted_string}\n");

            Console.WriteLine("\nPress any key to exit");
            Console.ReadKey();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 生成公私钥对
        /// </summary>
        public static void CreateRSAKey()
        {
            var keyList    = RsaKeyGenerator.XmlKey(2048);
            var privateKey = keyList[0];
            var publicKey  = keyList[1];

            // XML
            Console.WriteLine(RsaKeyGenerator.XmlKey(2048)[0]);
            Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine(RsaKeyGenerator.XmlKey(2048)[1]);
            Console.WriteLine("================================================================================");
            // Pkcs1
            Console.WriteLine(RsaKeyGenerator.Pkcs1Key(2048, true)[0]);
            Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine(RsaKeyGenerator.Pkcs1Key(2048, true)[1]);
            Console.WriteLine("================================================================================");
            // Pkcs8
            Console.WriteLine(RsaKeyGenerator.Pkcs8Key(2048, true)[0]);
            Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine(RsaKeyGenerator.Pkcs8Key(2048, true)[1]);

            Console.ReadKey();
        }
Ejemplo n.º 10
0
        public RsaKeyPair(RsaKeyType keyType, int keySize)
        {
            List <string> keys;

            switch (keyType)
            {
            case RsaKeyType.XML:
                keys = RsaKeyGenerator.XmlKey(keySize);
                break;

            case RsaKeyType.Pkcs1:
                keys = RsaKeyGenerator.Pkcs1Key(keySize, false);
                break;

            case RsaKeyType.Pkcs8:
                keys = RsaKeyGenerator.Pkcs8Key(keySize, false);
                break;

            default:
                throw new ArgumentException("Key类型不存在");
            }
            PrivateKey = keys[0];
            PublicKey  = keys[1];
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 获得私钥和公钥
 /// [0]=privateKey  私钥
 /// [1]=publicKey  公钥
 /// </summary>
 /// <returns></returns>
 public static List <string> GetKey()
 {
     return(RsaKeyGenerator.Pkcs1Key(2048, true));
 }