c# - OpenSSL.Net 创建证书 509x

标签 c# openssl

我下载了这个包装器 OpenSSL.Net,我将集成到我的项目中,该项目包含一个 PKI 开发

  • 创建证书人员
  • 创建一个自签名 CA 证书
  • 用CA签了证书我找不到解决办法

最佳答案

您可以使用 X509CertificateAuthority 和 X509Certificate 类以编程方式使用 OpenSSL.NET 创建 SSL 证书。 您可以在 below link. 找到示例代码

###################################################
// Create a configuration object using openssl.cnf file.
OpenSSL.X509.Configuration cfg = new OpenSSL.X509.Configuration("Path to your openssl configuration file i.e. openssl.cnf");

// Create a root certificate authority which will have a self signed certificate.
OpenSSL.X509.X509CertificateAuthority RootCA = OpenSSL.X509.X509CertificateAuthority.SelfSigned(cfg, new SimpleSerialNumber(),"Disinguish name for your CA", DateTime.
Now, TimeSpan.FromDays(365));

// If you want the certificate of your root CA which you just create, you can get the certificate like this.
X509Certificate RootCertificate = rootCA.certificate;

// Here you need CSR(Certificate Signing Request) which you might have already got it from your web server e.g. IIS7.0.
string strCSR = System.IO.File.ReadAllText(@"Path to your CSR file");

// You need to write the CSR string to a BIO object as shown below.
OpenSSL.Core.BIO ReqBIO = OpenSSL.Core.BIO.MemoryBuffer();
ReqBIO.Write(strCSR);

// Now you can create X509Rquest object using the ReqBIO.
OpenSSL.X509.X509Request Request = new OpenSSL.X509.X509Request(reqBIO);

// Once you have a request object, you can create a SSL Certificate which is signed by the self signed RootCA.
OpenSSL.X509.X509Certificate certificate = RootCA.ProcessRequest(Request, DateTime.Now, DateTime.Now + TimeSpan.FromDays(365));

// Now you can save this certificate to your file system.
FileStream fs = new FileStream("Path to your file where you want to create the certificate with file name", FileMode.Create, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);
BIO bio = BIO.MemoryBuffer();
certificate.Write(bio);
string certString = bio.ReadString();
bw.Write(certString);
##############################################

关于c# - OpenSSL.Net 创建证书 509x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5763313/

相关文章:

c# - 在 Web API、 Entity Framework 中使用 n 层体系结构时,数据访问层中的上下文为空

c# - JSON.NET:反序列化和合并 JSON 字符串

c++ - 如何在 Ubuntu 上安装 OpenSSL 库?

azure - 如何修复 "ERROR: Invalid id_token. OpenSSL unable to verify data"

openssl - 通过代理服务器的 SSL 隧道

c# - 当配置中存在配置行时,Nhibernate.Util 导致 ProxyFactoryFactoryNotConfiguredException

c# - 领域模型与数据库模型不同吗?

c# - 显示 Silverlight 的 ComboBox 组 header

ruby-on-rails - 错误:执行 gem 时...(OpenSSL::X509::StoreError)

security - SSL 错误 : unable to get local issuer certificate