Validating Timestamp in Digital Signature

The process of validating a digital signature containing a timestamp using UniPDF will be shown in this guide.

Before you begin

You should get your API key from your UniCloud account.

If this is your first time using UniPDF SDK, follow this guide to set up a local development environment.

Project setup

Clone the project repository

In your terminal, clone examples repository using the following command. It contains the Go code we will be using for this guide.

git clone https://github.com/unidoc/unipdf-examples.git

Then navigate to the signatures folder in the unipdf-examples directory.

cd unipdf-examples/signatures

Configure environment variables

Configure your license key using the following command: Replace the UNIDOC_LICENSE_API_KEY with your API credentials from your UniCloud account.

Linux/Mac

export UNIDOC_LICENSE_API_KEY=PUT_YOUR_API_KEY_HERE

Windows

set UNIDOC_LICENSE_API_KEY=PUT_YOUR_API_KEY_HERE

How it works

The import section in line 8-17, imports the necessary dependencies. The init function authenticates library request by setting the license key using license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`)).

The main function which is defined in lines 30-85, contains the code that validates timestamp signatures. The function starts by checking the number of command line arguments and then getting the input path from the os.Args slice. This slice contains all the arguments given to the command.

A list of signature handlers is created in lines 51-58. Then the signatures are validated using reader.ValidateSignatures(handlers) and the result is saved to res in line 61. A slice that will contain time stamp validation results is created using timestampRes := make(map[int]model.SignatureValidationResult) in line 69. The for loop in lines 71-76, iterates through each result and finds only timestamp signatures using core.GetDict(item.Fields[0].V). If the SubFilter entry of the timestamp signatures dictionary has a value of ETSI.RFC3161, then the item is added to the list of validation result.

Then in lines 82-84, iterates through each timestamp validation result and prints the information.

Run the code

Run the code using the following command.

go run pdf_sign_validate_timestamp.go <INPUT_PDF_PATH>

Got any Questions?

We're here to help you.