Skip to Content
NexPDF

Long-term signatures (B-LTA)

Sign at PAdES B-LTA, add RFC 3161 document timestamps, renew archive timestamps and timestamp with your own TSA from a .NET MAUI app.

English

License module

Signature levels and document timestamps need the signatures module (Business tier and above). Verification needs the same module.

PAdES B-LTA keeps a signature verifiable for decades. On top of a timestamped signature with its validation data (B-LT), it adds a document timestamp: an RFC 3161 timestamp over the whole file. Before the timestamp authority's certificate expires, you add another one (an archive timestamp), and so on. Timestamps and validation data are fetched from the network, so the device must be online.

Every call on this page returns the complete new file as byte[]. Write those bytes as they are and show them with LoadAsync.

Sign at a chosen level

SignPkcs12 and NexPdfSdk.CompleteExternalSignature take a level option: B-B (signature only), B-T (plus a signature timestamp), B-LT (plus certificates, OCSP responses and CRLs) or B-LTA (plus a document timestamp). Every level above B-B needs tsa_url or a TSA callback.

var p12 = await File.ReadAllBytesAsync(p12Path);
var signed = await Task.Run(() => view.Document!.SignPkcs12(p12, password,
    """{"reason":"Approved","level":"B-LTA","tsa_url":"http://timestamp.example.com"}"""));

await File.WriteAllBytesAsync(Path.Combine(FileSystem.AppDataDirectory, "signed-lta.pdf"), signed);
await view.LoadAsync(signed);

timestamp (hash, field, reserved) configures the B-LTA document timestamp.

Add a document timestamp

NexPdfSdk.AddDocumentTimestampBytes(data, optionsJson) timestamps the bytes of a file, and doc.AddDocumentTimestamp(optionsJson) an open document. With ltv, it first adds the validation data of every earlier signature: a B-T file becomes B-LTA, and a B-LTA file gets its archive timestamp renewed.

using Nexdevit.NexPdf;

var lta = await Task.Run(() => NexPdfSdk.AddDocumentTimestampBytes(signedBytes,
    """{"tsa_url":"http://timestamp.example.com","ltv":true}"""));

Options: tsa_url (required without a TSA callback), hash (SHA-256, SHA-384 or SHA-512), field (default Timestamp1), reserved (default 16384) and ltv.

Your own TSA or HSM

NexPdfSdk.SetTsaCallback(callback) registers a timestamp authority of your own for the whole process: an HSM, a signing service, or a TSA behind your own HttpClient. The callback receives the DER RFC 3161 TimeStampReq and returns the DER TimeStampResp or TimeStampToken:

var http = new HttpClient();
NexPdfSdk.SetTsaCallback(request =>
{
    var content = new ByteArrayContent(request);
    content.Headers.ContentType = new("application/timestamp-query");
    using var response = http.PostAsync("https://tsa.example.com", content).GetAwaiter().GetResult();
    response.EnsureSuccessStatusCode();
    return response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult();
});

var signed = await Task.Run(() => view.Document!.SignPkcs12(p12, password, """{"level":"B-LTA"}"""));

It is used when no tsa_url is given: by AddDocumentTimestamp, NexPdfSdk.AddDocumentTimestampBytes, and by SignPkcs12 and NexPdfSdk.CompleteExternalSignature at B-T, B-LT or B-LTA; a tsa_url always wins. The callback is synchronous and may run on any thread that calls NexPDF (keep those calls off the UI thread, as above); do not call SetTsaCallback from inside it. An exception or an empty answer fails the call. NexPdfSdk.ClearTsaCallback() removes it.

PrepareDocumentTimestamp(optionsJson), NexPdfSdk.DocumentTimestampRequest(prepared, hash) and NexPdfSdk.CompleteDocumentTimestamp(prepared, token) timestamp with a service of your own, with HttpClient in between. See the .NET long-term signatures guide.

The signature timestamp and the validation data can also be added in steps, with your own HTTP: NexPdfSdk.SignatureTimestampRequest(data, hash) and NexPdfSdk.AddSignatureTimestamp(data, token) for B-T, then NexPdfSdk.LtvRequestsJson(data, responsesJson) (called again with the answers until it returns []) and NexPdfSdk.AddLtvWithResponses(data, responsesJson) for B-LT. See online signing in steps.

Check a B-LTA file

NexPdfSdk.ValidateLtaJson(data, trustRootsPem) checks, for each document timestamp, that its revision's DSS holds every certificate and revocation entry the earlier signatures and timestamps need, and verifies OCSP responses (signature, responder, responder chain, currency at the protecting timestamp, status):

using System.Text.Json.Nodes;

var lta = JsonNode.Parse(await Task.Run(() => NexPdfSdk.ValidateLtaJson(pdfBytes, rootsPem)))!;
StatusLabel.Text = lta["complete"]!.GetValue<bool>() ? "B-LTA complete" : "validation data missing";

Each entry of timestamps lists issues with a kind such as missing-certificate, missing-revocation, revoked or ocsp-not-current; the full list is in the .NET guide.

Verify

NexPdfSdk.VerifySignaturesJson reports every signature and every document timestamp, with document_timestamp (true for a timestamp, whose signer is the TSA) and pades_level (B-B, B-T, B-LT or B-LTA):

using System.Text.Json.Nodes;

var report = JsonNode.Parse(await Task.Run(() => NexPdfSdk.VerifySignaturesJson(pdfBytes)))!.AsArray();
foreach (var s in report)
    System.Diagnostics.Debug.WriteLine(
        $"{(s!["document_timestamp"]!.GetValue<bool>() ? "timestamp" : "signature")} {s["signer"]} {s["pades_level"]}");

See Digital signatures for signing in a MAUI app.

On this page