开发日记:C# 伪证书加密技术

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(03);
                
switch (kinds)
                {
                    
case 0://数字类
                        #region 数字
                        Random myRandom11 
= new Random((int)DateTime.Now.Ticks);
                        System.Threading.Thread.Sleep(
1);
                        
int number11 = myRandom11.Next(09);
                        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(6590);
                        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(97122);
                        result 
+= Convert.ToChar(number33).ToString();
                        
continue;
                        
#endregion
                    
defaultbreak;
                }
            }
            
#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;
}

作者:罗敏贵
邮箱:minguiluo@163.com
QQ群:34178394 建群 主要是寻找志同道合的人士一起学习和讨论自己的所学所思
出处:http://luomingui.cnblogs.com/
说明:专注于微软平台项目架构、熟悉设计模式、架构设计、敏捷个人和项目管理。现主要从事WinForm、ASP.NET、等方面的项目开发、架构、管理工作。文章为作者平时里的思考和练习,可能有不当之处,请博客园的园友们多提宝贵意见。
知识共享许可协议本作品采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可。

原文地址:https://www.cnblogs.com/luomingui/p/1987960.html