如何使用 X509 证书以编程方式对开放式 Office XML Docx 文档进行数字签名?

发布于 2024-10-05 11:11:12 字数 823 浏览 10 评论 0原文

我想使用 Java 或 C# 中的 X509 证书以编程方式对开放式 Office XML Docx 文档进行数字签名。

此链接使用 System.IO.Packaging 中的 PackageDigitalSignatureManager 在 C# 中出色地实现了这一点: http://blogs.infosupport.com/blogs/woutrv/archive/2007/02/24/Signing-Office-Open-XML-documents-using-the-Packaging-API.aspx

尽管如此工作正常,最后它会提示用户对话框,要求他提供经过身份验证的数字签名的 PIN 码。

您知道如何以编程方式设置此 PIN 码吗?

干杯


谢谢您的详细回答。 基本上,我使用的是电子 ID 智能卡,它具有用于签署数字文档的证书。

通常,我将 X509Certificate 类型的公钥传递给 PackageDigitalSignatureManager Sign() 方法。

此方法将对文档进行签名,但会提示用户输入 PIN 码,以便检索存储在智能卡中的私钥。

是否可以向 PackageDigitalSignatureManager 传递一个包含 PKCS12 文件中的公钥/私钥对的对象,然后它就不会提示用户输入 PIN 码。

干杯,

I want to programatically digitally sign an open office XML Docx document with X509 Certificate either in Java or C#.

This link does it brilliantly with C# using PackageDigitalSignatureManager from System.IO.Packaging:
http://blogs.infosupport.com/blogs/wouterv/archive/2007/02/24/Signing-Office-Open-XML-documents-using-the-Packaging-API.aspx

Altough this works fine, at the end it prompts a user dialog to ask him for a PIN Number for the authenticated digital signature.

Do you know how to set this PIN Number programatically?

Cheers


Thank you for the detailed answer.
Basically, I'm using an electronic ID smartcard, which has a certificate for signing digital documents.

Typically I pass a public key in X509Certificate type, to PackageDigitalSignatureManager Sign() method.

This method will sign the document, but will prompt the user for a PIN in order to retrieve the Private key stored in the smart card.

Isn't it possible to pass the PackageDigitalSignatureManager an Object which includes both the Public/Private key pair in a PKCS12 file, and then it won't prompt the user for a PIN number.

Cheers,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幽梦紫曦~ 2024-10-12 11:11:12

问题#2 的答案取决于您使用的技术,更重要的是,取决于证书的存储位置。

在 Java 密钥存储 (JKS) 中,证书受密码保护,并且这些密码以代码形式传递。

在 Windows 证书存储(.NET 加密类使用的位置)中,证书使用 PIN 进行保护,大多数加密提供商无法通过代码设置该 PIN(有扩展命令来设置 PIN,但大多数提供商不支持它),并且用户需要手动确认对私钥的访问。

如果您使用存储在 PKCS12 文件中的证书,则该文件的密码也会在代码中设置。

而且,如果您有兴趣,我们还提供了用于在 .NET 中签署 Office 文档的组件(检查在这里)。与大多数示例代码不同,它们得到维护和支持。

The answer to question #2 depends on what technology you use and, more importantly, where the certificate is stored.

In Java Key Storage (JKS) certificates are protected with passwords and those passwords are passed in code.

In Windows Certificate Storage (location that .NET cryptography classes use) certificates are protected using PIN which can not be set by code for most cryptoproviders (there's extension command to set the PIN but most providers don't support it) and the user needs to confirm access to the private key by hand.

If you use certificate stored in PKCS12 file, then the password for the file is also set in code.

And, well, we offer components for signing office documents in .NET, if you are interested (check here). They are maintained and supported, unlike most sample code.

Spring初心 2024-10-12 11:11:12

MSDN 中有一个答案涵盖了它。
需要3个步骤

There is an answer in MSDN That covers it.
3 steps necessary

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文