如何生成 .pfx 文件?
有没有办法创建 .pfx 文件来签署文档, 我找到了一个名为 x509 证书生成的程序,但我想知道它是否可以使用 c# 在代码中生成。
Is there any way to create .pfx files in order to sign documents,
I've found a program called x509 Certificate Generate,but I want to know if it can be generated in code using c#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
有一个 Microsoft 命令行工具 makecert 可用于生成证书。它是 Windows SDK 的一部分。在我的机器上有六个版本,例如在
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64
中。然后,您可以在代码中启动一个进程来使用适当的参数运行可执行文件。There is a Microsoft command-line tool makecert that can be used to generate certificates. It's part of the Windows SDK. On my machine there are half a dozen versions e.g. in
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64
. Then in your code you can start a process to run the executable with the appropriate parameters.您可以查看 Bouncy Castle API,可用于使用C#生成证书。
You could check out the Bouncy Castle API, it can be used to generate certificates using C#.
首先,使用自签名证书签署文档没有任何意义,除非您的组织中有自定义 PKI 层次结构(在后一种情况下,您需要充分了解自己在做什么,但情况似乎并非如此)。
PFX 是一个或多个带有关联私钥的证书的容器。所以你不会生成“PFX 文件”。您生成密钥对并创建证书,然后可以将其导出到 PFX 文件或其他格式。
如上所述,BouncyCastle 可以生成证书,我们的 SecureBlackbox 库也可以生成证书并将其保存到多种不同格式或从多种不同格式加载它们。
First of all, signing documents with self-signed certificates makes no sense unless you have custom PKI hierarchy in your organization (and in the latter case you need to know well what you are doing, which seems to be not the case).
PFX is a container for one or more certificates with associated private keys. So you don't generate "PFX file". You generate a keypair and create a certificate, which can then be exported to PFX file or to other format.
As mentioned above, BouncyCastle can generate certificates, and our SecureBlackbox library also can generate certificates and save and load them to/from many different formats.
您可以使用 OpenSSL.NET 库来实现此目的。
这是如何执行此操作的代码示例:
You can use OpenSSL.NET library for this.
Here is the code example how to do it:
如果您阅读@David Clarke 的答案提到的有关 makecert 的信息,您会发现要满足您的要求,您只需要一个用 .NET 编写的托管 makecert。
幸运的是,Mono 的人很久以前就实现了这个,
https ://github.com/mono/mono/blob/master/mcs/tools/security/makecert.cs
If you read about makecert like @David Clarke's answer refers to, you will see to fulfill your requirement, you just need a managed makecert written in .NET.
Luckily the Mono guys have implemented this a long time ago,
https://github.com/mono/mono/blob/master/mcs/tools/security/makecert.cs
您可以使用adobe reader进行数字签名
如果您使用的是adobe x,
-然后转到左起第三个选项
- 在这里您可以看到签名设置
-打开这个并去添加id
- 只需输入您的详细信息,您就可以完成 .pfx 文件,无论您在哪里浏览它......
- 有效期为6年
You can make digital signature by using adobe reader
if you are using adobe x
-then go to 3rd option from left
-here you can see signing setting
-open this and go to add id
-just enter your details and your are done .pfx file is ready where ever you browsed it....
-it is valid for 6 years