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(); }
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(); }
/// <summary> /// XML格式的RSA密钥 /// </summary> /// <returns></returns> public static string CreateXMLKey() { var keyList = RsaKeyGenerator.XmlKey(2048); var privateKey = keyList[0]; var publicKey = keyList[1]; return($"私钥:{privateKey}\n公钥:{publicKey}"); }
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); }
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(); }
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(); }
/// <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(); }
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]; }
private static void Main(string[] args) { var input = ",130680807779,"; // 取匹配 var matches = Regex.Matches(input, @"(1)\d{10}") .Select(m => m.Value) .ToList(); matches = Regex.Matches(",1306808077701234,", @"(1)\d{10,20}") .Select(m => m.Value) .ToList(); matches = Regex.Matches("17703430350,,", @"(1)\d{10,20}") .Select(m => m.Value) .ToList(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var str = "筷开动1234Abc"; var gbk = Encoding.GetEncoding("GBK").GetBytes(str); var gbkToStr = Encoding.GetEncoding("GBK").GetString(gbk); Console.WriteLine($"GBK是否相同:{str == gbkToStr}\n"); Console.WriteLine("获取Ticks测试------start-------"); for (var i = 0; i < 10; i++) { var ticks = DateTime.Now.Ticks.ToString(); Console.WriteLine($" {i} ticks:{ticks} len:{ticks.Length}"); } Console.WriteLine("获取Ticks测试------end-------"); var keyList = RsaKeyGenerator.XmlKey(2048); var privateKey = keyList[0]; var publicKey = keyList[1]; var source = "1234再看看看!@#¥#!#"; var rsaXmlUtil = new RsaXmlUtil(Encoding.UTF8, publicKey, privateKey); var encryptData = rsaXmlUtil.Encrypt(source, RSAEncryptionPadding.OaepSHA256); Console.WriteLine("加密测试:"); Console.WriteLine(" 加密后的数据:{0}", encryptData); var decryptData = rsaXmlUtil.Decrypt(encryptData, RSAEncryptionPadding.OaepSHA256); Console.WriteLine("\n 解密后的数据:{0}", decryptData); Console.WriteLine(" 解密后的数据与源数据相同:{0}", source == decryptData); Console.WriteLine("\n签名测试:"); var signData = rsaXmlUtil.SignData(source, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); Console.WriteLine(" 签名值:{0}", signData); var verifyRet = rsaXmlUtil.VerifyData(source, signData, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); Console.WriteLine(" 验证签名:{0}", verifyRet); Console.WriteLine("\n签名转换:"); var privatePkcs1 = RsaKeyConvert.PrivateKeyXmlToPkcs1(privateKey); var publicPkcs1 = RsaKeyConvert.PublicKeyXmlToPem(publicKey); Console.WriteLine(" private key of Pkcs1:{0}", privatePkcs1); Console.WriteLine(" public key of Pkcs1:{0}", publicPkcs1); Console.WriteLine("Guid转换String测试.---开始---"); var id = Guid.NewGuid(); var idString = id.ToString("N"); Console.WriteLine("Guid.ToString(N)={0},原guid:{1}", idString, id); var idFromString = Guid.ParseExact(idString, "N"); Console.WriteLine("Guid.ParseExact(idString,N):{0} ,是否相等:{1}", idFromString, idFromString == id); Console.WriteLine("Guid转换String测试.---结束。"); Console.ReadLine(); }