x509数字证书导入-然后删除本身

Posted Free Time Worker

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了x509数字证书导入-然后删除本身相关的知识,希望对你有一定的参考价值。

 static void Main(string[] args)
        {
            Console.WriteLine("正在执行数字证书写入");
            try
            {
                X509Certificate2 certificateClient = new X509Certificate2

(global::X509Build.Properties.Resources.Client, "123",X509KeyStorageFlags.PersistKeySet);
                X509Certificate2 Server = new X509Certificate2

(global::X509Build.Properties.Resources.SaltTraceServerPublic);
X509Store store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser);
                store.Open(OpenFlags.ReadWrite);
                store.Remove(certificateClient);
                store.Add(certificateClient);
                store.Remove(certificateServer);
                store.Add(certificateServer);
                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();
                //Console.WriteLine("正在写入数字证书,请稍等");
                //Thread.Sleep(3000);
                Thread t = new Thread(() =>
                {
                    Process proc = new Process();
                    proc.StartInfo.FileName = delfilepath;
                    proc.StartInfo.CreateNoWindow = false;
                    proc.StartInfo.UseShellExecute = false;
                    proc.Start();
                });
                t.Start();
                Console.WriteLine("数字证书写入成功");
            }
            catch
            {
                Console.WriteLine("数字证书写入失败");
                Console.ReadKey();
            }
       }

 

以上是关于x509数字证书导入-然后删除本身的主要内容,如果未能解决你的问题,请参考以下文章

Android App 安全的HTTPS 通信

请教使用OpenSSL读写X509数字证书,有代码

使用私钥将 X509Certificate2 导出到字节数组

比较java中的2 x509证书

使用充气桥X509v3CertificateBuilder生成X509证书

使用 X509 证书进行消息签名