如何创建一个使用C#中的自签名的证书?创建一个、证书

2023-09-02 11:49:45 作者:放开你的理由

我需要创建一个自签名证书(适用于本地加密 - 它不是用来保护通信),使用C#。

I need to create a self-signed certificate (for local encryption - its not used to secure communications), using C#.

我已经看到了使用的P / Invoke 与Crypt32.dll,但它们是复杂的,它很难更新参数 - 我也想避免P /如果在所有可能调用

I've seen some implementations that use P/Invoke with Crypt32.dll, but they are complicated and its hard to update the parameters - and I would also like to avoid P/Invoke if at all possible.

我并不需要的东西是跨平台的 - 只有在Windows上运行的是对我不够好

I don't need something that is cross platform - running only on Windows is good enough for me.

理想的结果是,我可以用插入到Windows证书存储区或导出到一个PFX文件的X509Certificate2对象。

Ideally the result would be an X509Certificate2 object that I can use to insert into the Windows certificate store or export to a PFX file.

推荐答案

本实现使用 CX509CertificateRequestCertificate COM对象(和朋友 - 的