zoukankan      html  css  js  c++  java
  • x509数字证书导入-然后删除自身

    这种程序的使用场景,需要给客户一个证书,但不能把证书直接给他让他安装,程序中需要用到给客户的私钥,但又不允许客户将这个证书再去授权给其它人。

    重点并不是代码,是如何对用户隐藏需要添加的资源 ,以文本为例

    1.将文件添加到资源中,直接粘贴就可以

    2.打开解决方案,

    修改文件属性 生成操作为嵌入的资源。如果config没有什么特殊需要配置的,那么只需要给客户一个exe就可以了

     下边是代码

            static void Main(string[] args)
            {
                Console.WriteLine("正在执行数字证书写入");
                try
                {
                    X509Certificate2 certificateClient = new X509Certificate2(global::X509Build.Properties.Resources.Client, "123",X509KeyStorageFlags.PersistKeySet);
             X509Store store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser);
                    store.Open(OpenFlags.ReadWrite);
                    store.Remove(certificateClient);
                    store.Add(certificateClient);
                    store.Close();
              string delfilepath = AppDomain.CurrentDomain.BaseDirectory + "del.bat";
                    FileStream fs = new FileStream(delfilepath, FileMode.Create);
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine("@echo off ");
                    sw.WriteLine("ping -n 1 127.1>nul");
                    sw.WriteLine("del X509Build.exe");
                    sw.WriteLine("del %0");
                    sw.Close(); sw.Dispose();
                    fs.Close(); fs.Dispose();
                    Thread t = new Thread(() =>
                    {
                        Process proc = new Process();
                        proc.StartInfo.FileName = delfilepath;
                        proc.StartInfo.CreateNoWindow = false;
                        proc.StartInfo.UseShellExecute = false;
                        proc.Start();
                    });
                    t.Start();
                }
                catch
                {
                    Console.WriteLine("数字证书写入失败");
                    Console.ReadKey();
                }
           }
  • 相关阅读:
    (四)使用SecureCRTPortable 连接虚拟机 安装jdk
    (三)配置本地YUM源
    (二) 配置 centos6.7
    docker学习
    linux磁盘情况查看处理
    日志文件切割
    已有项目创建git
    微擎绑定开放平台后依然拿不到唯一id?
    php7 安装mongodb扩展
    mongodb 学习
  • 原文地址:https://www.cnblogs.com/zzfstudy/p/6244521.html
Copyright © 2011-2022 走看看