简体   繁体   English

使用来自当前用户商店的 x509 证书签署 pdf

[英]Sign a pdf with x509certificate from current user store

first of all please note that I'm quite new to this platform and therefore not used to the rules or "best practices", so please let me know if there's anything i should edit.首先请注意,我对这个平台很陌生,因此不习惯规则或“最佳实践”,所以如果有什么我应该编辑的,请告诉我。

But now, here's my problem:但现在,这是我的问题:

I want to sign a pdf document with a certificate from the current user store.我想使用当前用户存储中的证书签署 pdf 文档。 For this task, I'm not allowed to use libraries that require a license, so basically everything i use has to be open source.对于这个任务,我不允许使用需要许可证的库,所以基本上我使用的所有东西都必须是开源的。 The private key of the certificate that i have to use for signing is set to unexportable.我必须用于签名的证书的私钥设置为不可导出。 I already managed to complete the task by using the "Syncfusion PDF" library, but unfortunately, it's not open source.我已经设法通过使用“Syncfusion PDF”库完成了这项任务,但不幸的是,它不是开源的。

Since I'm quite new to programming and especially c# i now struggle to find a solution without using Syncfusion.由于我对编程非常陌生,尤其是 c#,我现在很难在不使用 Syncfusion 的情况下找到解决方案。 Hope somebody can help:)希望有人可以提供帮助:)

Here's the code WITH Syncfusion.这是带有 Syncfusion 的代码。 it works perfectly fine:它工作得很好:

Stream stream = new FileStream(src, FileMode.OpenOrCreate);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
PdfLoadedSignatureField field = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
X509Certificate2 digitalID = collection[0];
PdfCertificate certificate = new PdfCertificate(digitalID);
PdfSignature pdf1 = new PdfSignature(loadedDocument, page, certificate, "Signature", field);
field.Signature = pdf1;
loadedDocument.Save(stream);
loadedDocument.Close(true);

We have analyzed your requirement.我们已经分析了您的要求。 But we can only help if you have any doubts in Syncfusion library.但是,如果您对 Syncfusion 库有任何疑问,我们只能提供帮助。

Note : I work for Syncfusion.注意:我为 Syncfusion 工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM