I am signing pdfs using a USB Certificate Token. I noticed some threads regarding including the private key and LTV Enabled pdf signing, but with a usb certificate token I cannot load the private key the same way as with a PFX or certificate store certificate with private key.
How do I generate a LTV Enabled certificate using a USB Certificate Token?
Using the below code, I get a signed PDF but it is not LTV enabled:
Signature is not LTV enabled and will expire after 2010/07/15 09:23:41 -01'00'
I am instead looking for:
Signature is LTV enabled
- Code: Select all
PdfDocument doc = new PdfDocument("Test.pdf");
PdfPageBase page = doc.Pages[0];
X509Store store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySubjectName, "My USB Token Cert", true);
X509Certificate2 cert = certs[0];
PdfCertificate pdfcert = new PdfCertificate(cert);
PdfSignature signature = new PdfSignature(doc, page, pdfcert, "signature");
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges;
signature.GraphicsMode = GraphicMode.SignDetail;
document.FileInfo.IncrementalUpdate = false;
document.CompressionLevel = PdfCompressionLevel.Best;
doc.SaveToFile("Signed_Test.pdf");
doc.Close();