C# 伪证书加密技术,大家看到这个标题可能很惊讶 是的,我把,过期时间,机器码都存到文件里去了,然后在程序里调用。
生成证书
这个是 生成的证书。
生成证书代码:
/// <summary> /// 生成证书,并保存到指定位置,默认保存在当前用户桌面 /// </summary> public void CreatePfxFile(string SavePaht) { if (McieCode.Length == 0){ McieCode = MachineCode.GetCpuInfo(); } StringBuilder builder = new StringBuilder(); builder.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); builder.AppendLine("<root>"); builder.AppendLine(" <guid>" + Guid + "</guid>"); builder.AppendLine(" <name>" + Name + "</name>"); builder.AppendLine(" <address>" + Address + "</address>"); builder.AppendLine(" <phone>" + Phone + "</phone>"); builder.AppendLine(" <postalcode>" + Postalcode + "</postalcode>"); builder.AppendLine(" <machinecode>" + McieCode + "</machinecode>"); builder.AppendLine(" <deadline>" + Deadline + "</deadline>"); builder.AppendLine("</root>");
string des = DESEncrypt.Encode(builder.ToString()); if (SavePaht.Length == 0) { string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); SavePaht = desktop + "\\SoftDog.pfx"; } StreamWriter sw = File.AppendText(SavePaht); sw.WriteLine(des); sw.Flush(); sw.Close(); }
证书管理
使用证书
证书使用步骤:
1:将生成的证书 文件复制到系统目录下的system32文件夹下。
2:将 SoftDog.IsDogDalne(); 写到你的WEB项目否WIN项目里就可以使用证书了。
其他
生成序列号:
1111-1100-0000-008y
代码如下:
private string CreateRandomNum() { string result = ""; #region 生成随机号 for (int i = 0; i < 16; i++) { Random myRandom1 = new Random((int)DateTime.Now.Ticks); System.Threading.Thread.Sleep(1); int kinds = myRandom1.Next(0, 3); switch (kinds) { case 0://数字类 #region 数字 Random myRandom11 = new Random((int)DateTime.Now.Ticks); System.Threading.Thread.Sleep(1); int number11 = myRandom11.Next(0, 9); result += number11.ToString(); continue; #endregion case 1://大写字母类 #region 大写字母类 Random myRandom22 = new Random((int)DateTime.Now.Ticks); System.Threading.Thread.Sleep(1); int number22 = myRandom22.Next(65, 90); result += Convert.ToChar(number22).ToString(); continue; #endregion case 2://小写字母类 #region 小写字母类 Random myRandom33 = new Random((int)DateTime.Now.Ticks); System.Threading.Thread.Sleep(1); int number33 = myRandom33.Next(97, 122); result += Convert.ToChar(number33).ToString(); continue; #endregion default: break; } } #endregion #region 加"-" string newstring=""; for (int i = 1; i <= result.Length; i++) { newstring+=result[i-1]; if (i % 4 == 0 && i != result.Length) newstring += "-"; } result = newstring; #endregion return result; }
生成序列号:
1111-1100-0000-008y
代码如下:
private string CreateRandomNum() { string result = ""; #region 生成随机号 for (int i = 0; i < 16; i++) { Random myRandom1 = new Random((int)DateTime.Now.Ticks); System.Threading.Thread.Sleep(1); int kinds = myRandom1.Next(0, 3); switch (kinds) { case 0://数字类 #region 数字 Random myRandom11 = new Random((int)DateTime.Now.Ticks); System.Threading.Thread.Sleep(1); int number11 = myRandom11.Next(0, 9); result += number11.ToString(); continue; #endregion case 1://大写字母类 #region 大写字母类 Random myRandom22 = new Random((int)DateTime.Now.Ticks); System.Threading.Thread.Sleep(1); int number22 = myRandom22.Next(65, 90); result += Convert.ToChar(number22).ToString(); continue; #endregion case 2://小写字母类 #region 小写字母类 Random myRandom33 = new Random((int)DateTime.Now.Ticks); System.Threading.Thread.Sleep(1); int number33 = myRandom33.Next(97, 122); result += Convert.ToChar(number33).ToString(); continue; #endregion default: break; } } #endregion #region 加"-" string newstring=""; for (int i = 1; i <= result.Length; i++) { newstring+=result[i-1]; if (i % 4 == 0 && i != result.Length) newstring += "-"; } result = newstring; #endregion return result; }
|
请发表评论