Error when digitally signing a pdf #188
Unanswered
NintendoPlayer
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Would be good to have some code to replicate the issue. The document is signed after it was saved, so that's the time when the certificate is actually used. The exception does not come from PDFsharp, so maybe you can find an answer on the Internet. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I'm trying digital signing with preview PDFsharp Core 6.2.0 Preview 1 on a NET. 8 project. I get my certificate from the certificates store and sign the pdf. Everything goes well until I save the document. I get this error:
System.Security.Cryptography.CryptographicException: 'Provider could not perform the action since the context was acquired as silent.'
I don't know what really is the issue, any thoughts?
Thanks!
Here is the code:
// Some code designing my pdf
//After that I call this function to sign the pdf
pdfDocumentOutput = signPdfWithDigitalCertificatev2(pdfDocumentOutput)
//Then I save the pdf
pdfDocumentOutput .Save(newFullFileName); -> Here is the line that prompts the issue above.
private PdfSharp.Pdf.PdfDocument signPdfWithDigitalCertificatev2(PdfSharp.Pdf.PdfDocument pdfDocumentOutput)
{
//Here I select the correct certificate with native popup window
var store2 = new X509Store();//(StoreName.My, StoreLocation.LocalMachine);
store2.Open(OpenFlags.ReadOnly);
var selectedCertificate = X509Certificate2UI.SelectFromCollection(
store2.Certificates,
"Title",
"MSG",
X509SelectionFlag.SingleSelection);
int signatureWidth = 210;
int signatureHeight = 150;
//This code is almost the same from the samples on Github
var options = new DigitalSignatureOptions()
{
ContactInfo = "Me",
Location = "Spain",
Reason = "I'm the authos",
Rectangle = new XRect(pdfDocumentOutput.Pages[0].Width / 2 - signatureWidth / 2, 750, signatureWidth, signatureHeight),
AppearanceHandler = new SignatureAppearanceHandler()
};
// I sign the pdf with the certificate I selected
var pdfSignatureHandler = DigitalSignatureHandler.ForDocument(pdfDocumentOutput,
new PdfSharpDefaultSigner(selectedCertificate[0], PdfMessageDigestType.SHA256, true ? new Uri("http://timestamp.apple.com/ts01") : null),
options);
return pdfDocumentOutput;
}
Beta Was this translation helpful? Give feedback.
All reactions