Digital signatures
Verify signatures and sign PDFs with a PKCS#12 file from a .NET MAUI app with the NexPDF engine.
License module
Signing, LTV and verification (with or without your own roots) need the signatures module
(Business tier and above).
PdfView has no signing UI (1.1 included); signing and verification run through the engine API.
Verify the signatures of a file
using System.Text.Json.Nodes;
using Nexdevit.NexPdf;
var report = JsonNode.Parse(await Task.Run(() => NexPdfSdk.VerifySignaturesJson(pdfBytes)))!.AsArray();
foreach (var s in report)
{
var ok = s!["digest_ok"]!.GetValue<bool>() && s["signature_ok"]!.GetValue<bool>();
System.Diagnostics.Debug.WriteLine($"{s["signer"]} {s["level"]} {(ok ? "valid" : "INVALID")}");
}Sign with a PKCS#12 file
Signing returns the complete signed file. Write those bytes as they are and show them with
LoadAsync; saving the document object again would break the signature.
var p12 = await File.ReadAllBytesAsync(p12Path);
var signed = await Task.Run(() => view.Document!.SignPkcs12(p12, password,
"""{"reason":"Approved","appearance":{"page":0,"rect":[360,60,560,120],"text":"Signed"}}"""));
var path = Path.Combine(FileSystem.AppDataDirectory, "signed.pdf");
await File.WriteAllBytesAsync(path, signed);
await view.LoadAsync(signed);Keep the PKCS#12 password in SecureStorage, not in the app bundle.
Options also take level (B-B, B-T, B-LT or B-LTA) and timestamp for the B-LTA document
timestamp; see Long-term signatures. Verification reports
pades_level and document_timestamp for each entry.
A drawn signature
A handwritten signature without cryptography is an ink annotation (annotations module):
view.Document!.AddInkSignature(view.CurrentPage, "#111827", 1.5, "300,120;320,130;340,118|350,125;380,128");
await view.ReloadAsync();External signing with a smart card or a cloud key, timestamps and LTV are in the .NET signatures guide. For PAdES B-LTA, document timestamps and archive timestamp renewal, see Long-term signatures.