Hello!
could you help me?
I'm trying to sign a pdf file with a smart card and the private key is not included.... normally it would open a model for insert the password, but I just got an error...
Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException: 'The keyset is not defined.'
My Code c#
using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
//Creates a new PDF document
PdfDocument document = new PdfDocument();
//Adds a new page
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(fcollection, "Selecione o Certificado", "Selecione o certificado da lista abaixo para assinar seu documento", X509SelectionFlag.SingleSelection);
store.Close();
X509Certificate2 certificate = new X509Certificate2();
if (scollection.Count != 0)
certificate = (X509Certificate2)scollection[0];
PdfCertificate pdfCertificate = new PdfCertificate(certificate);
//Creates a digital signature
PdfSignature signature = new PdfSignature(document, page, pdfCertificate, "DigitalSignature");
signature.Bounds = new RectangleF(40, 40, 350, 100);
//Create a font to draw text.
PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 15);
//Drawing text, shape, and image into the signature appearance.
signature.Appearance.Normal.Graphics.DrawRectangle(PdfPens.Black, PdfBrushes.White, new RectangleF(50, 0, 300, 100));
signature.Appearance.Normal.Graphics.DrawString("Digitally Signed by Syncfusion", font, PdfBrushes.Black, 120, 17);
signature.Appearance.Normal.Graphics.DrawString("Reason: Testing signature", font, PdfBrushes.Black, 120, 39);
signature.Appearance.Normal.Graphics.DrawString("Location: USA", font, PdfBrushes.Black, 120, 60);
//Changing the digital signature standard and hashing algorithm.
signature.Settings.CryptographicStandard = CryptographicStandard.CADES;
signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA512;
System.IO.Stream stream = new System.IO.FileStream("pdf3.pdf", FileMode.Create);
//Save the document
document.Save(stream);
//Close the document
document.Close(true);