• 大小: 0.06M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2020-12-26
  • 语言: C#
  • 标签: C#  证书  pfx  

资源简介

    我的项目当中,考虑到安全性,需要为每个客户端分发一个数字证书,同时使用数字证书中的公私钥来进行数据的加解密。为了完成这个安全模块,特写了如下一个DEMO程序,该DEMO程序包含的功能有:

1:调用.NET2.0的MAKECERT创建含有私钥的数字证书,并存储到个人证书区;

2:将该证书导出为pfx文件,并为其指定一个用来打开pfx文件的password;

3:读取pfx文件,导出pfx中公钥和私钥;

4:用pfx证书中的公钥进行数据的加密,用私钥进行数据的解密;

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Security.Cryptography.X509Certificates;
using System.IO;

namespace WindowsFormsAppPfs
{
    public sealed class DataCertificate   
    {  
        #region 生成证书   
        ///    
        /// 根据指定的证书名和makecert全路径生成证书(包含公钥和私钥,并保存在MY存储区)   
        /// 
   
        ///    
        ///    
        ///    
        public static bool CreateCertWithPrivateKey(string subjectName string makecertPath)   
        {   
            subjectName = “CN=“ + subjectName;   
            string param = “ -pe -ss my -n \““ + subjectName + “\“ “;   
            try  
           

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      22528  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\bin\Debug\WindowsFormsAppPfs.exe

     文件      36352  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\bin\Debug\WindowsFormsAppPfs.pdb

     文件      14328  2010-06-10 10:09  WindowsFormsAppPfs\WindowsFormsAppPfs\bin\Debug\WindowsFormsAppPfs.vshost.exe

     文件        490  2009-06-11 05:14  WindowsFormsAppPfs\WindowsFormsAppPfs\bin\Debug\WindowsFormsAppPfs.vshost.exe.manifest

     文件       8810  2010-06-09 17:46  WindowsFormsAppPfs\WindowsFormsAppPfs\DataCertificate.cs

     文件       8695  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\Form1.cs

     文件      29290  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\Form1.Designer.cs

     文件       5814  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\Form1.resx

     文件        777  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\obj\Debug\WindowsFormsAppPfs.csproj.FileListAbsolute.txt

     文件        847  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\obj\Debug\WindowsFormsAppPfs.csproj.GenerateResource.Cache

     文件      22528  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\obj\Debug\WindowsFormsAppPfs.exe

     文件        180  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\obj\Debug\WindowsFormsAppPfs.Form1.resources

     文件      36352  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\obj\Debug\WindowsFormsAppPfs.pdb

     文件        180  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\obj\Debug\WindowsFormsAppPfs.Properties.Resources.resources

     文件        479  2010-06-09 17:23  WindowsFormsAppPfs\WindowsFormsAppPfs\Program.cs

     文件       1368  2010-06-09 17:23  WindowsFormsAppPfs\WindowsFormsAppPfs\Properties\AssemblyInfo.cs

     文件       2886  2010-06-09 17:23  WindowsFormsAppPfs\WindowsFormsAppPfs\Properties\Resources.Designer.cs

     文件       5612  2010-06-09 17:23  WindowsFormsAppPfs\WindowsFormsAppPfs\Properties\Resources.resx

     文件       1103  2010-06-09 17:23  WindowsFormsAppPfs\WindowsFormsAppPfs\Properties\Settings.Designer.cs

     文件        249  2010-06-09 17:23  WindowsFormsAppPfs\WindowsFormsAppPfs\Properties\Settings.settings

     文件       3414  2010-06-09 17:46  WindowsFormsAppPfs\WindowsFormsAppPfs\WindowsFormsAppPfs.csproj

     文件        944  2010-06-09 17:23  WindowsFormsAppPfs\WindowsFormsAppPfs.sln

    ..A..H.     19456  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs.suo

     目录          0  2010-06-09 17:44  WindowsFormsAppPfs\WindowsFormsAppPfs\obj\Debug\Refactor

     目录          0  2010-06-09 17:23  WindowsFormsAppPfs\WindowsFormsAppPfs\obj\Debug\TempPE

     目录          0  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\bin\Debug

     目录          0  2010-06-10 10:12  WindowsFormsAppPfs\WindowsFormsAppPfs\obj\Debug

     目录          0  2010-06-09 17:23  WindowsFormsAppPfs\WindowsFormsAppPfs\bin

     目录          0  2010-06-09 17:23  WindowsFormsAppPfs\WindowsFormsAppPfs\obj

     目录          0  2010-06-09 17:23  WindowsFormsAppPfs\WindowsFormsAppPfs\Properties

............此处省略5个文件信息

评论

共有 条评论