In the code below with the call to ConfigureTimestamp() - I receive an exception for lost private key.
If I comment out the timestamp I am able to digitally sign the PDF and reviewing in Adobe Review I see the signature is invalid with one of the reasons - "Signing time is from the clock on the signer's computer"
- Code: Select all
private static string ApplySignatures()
{
string sourceFilename = Path.Combine(_filePath, "TestPDF_20220624_0424.pdf");
using (var pdf = new PdfDocument(sourceFilename))
{
try
{
var client = new CertificateClient(vaultUri: new Uri(_vaultUrl), credential: new DefaultAzureCredential());
var cert = client.GetCertificate(_certName);
var pdfCert = new PdfCertificate(cert.Value.Cer);
//Create a PdfSignature object
var signature = new PdfSignature(pdf, pdf.Pages[pdf.Pages.Count - 1], pdfCert, "Authorization Signature");
signature.LocationInfo = "Cleveland, OH";
signature.Reason = "Authorized";
//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;
signature.ConfigureTimestamp("https://freetsa.org/tsr");
//Save to another PDF file
var signedDocName = Path.Combine(_filePath, $"Spire_SignedDocument_{DateTime.UtcNow.ToString("yyyyMMdd-mmss")}.pdf");
pdf.SaveToFile(signedDocName);
pdf.Close();
return signedDocName;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return "";
}
}
}