Signature Service
The Signature Service allows you to create and verify signatures, as well as creating a hash/digest of input data
Initialize the Signature Service
The Signature service wants to have a Key Provider as single argument. If you want to use multiple Key Providers you will have to instantiate multiple signature services.
Determine Sign Input
Determines the bytes that will serve as input for the digest
or createSignature
methods.
Since multiple signature types are supported the configuration and key are required te determine the appropriate mode of extraction. For instance
Pades signatures do not need a simple digest of the full file contents, depending on whether the PDF document already contains signatures. This method
should be called first when creating a signature.
The below SignInput object could be used directly for the createSignature method or a digest can be created first, so that the input data will never traverse a network if a remote Sign REST API or remote Hardware Security Module is being used.
Create a hash digest for additional privacy and security
The digest
method creates a hash digest out of the SignInput. The hash digest is a one way function that creates the fingerprint of the file. From
the digest you cannot get back to the original input data/document. This means any Personally Identifiable Data or Data which needs to stay private
will not be available to methods which need access to a remote REST API or remote Hardware Security Module. This obviously is preferable from a
privacy and security perspective. It allows users of the library to execute all methods on premise and then depending on the chosen Key
Provider sign the data either on premise or remotely. In no circumstance will the input data leave the premise.
Notice that the below SignInput object is different from the passed in SignInput. The input value is shorter as it now is a hash digest. The signMode
moved from DOCUMENT
to DIGEST
so that the createSignature
method knows not to create a hash digest out of the input anymore.
Create the signature
The default Signature Service implementations delegate this method to the corresponding method of the KeyProvider, given most KeyProviders to not expose private keys for security reasons.
Depending on the Key Provider settings this method could be traversing the network as it might call a signature REST API, or use a network/cloud based Hardware Security Module containing the private key to sign. As such we advise to create the digest beforehand so original documents/data is not being sent. Only the hash digest will traverse the network.
Signing the original data, merging the signature
This method takes the original input document, the created signature and merges them together to provide a signed output document. It needs access to the configuration to know how and where the signature should be merged with the document.
The result of the above is a new file which is the input PDF, but now signed.
simpleSign an original data
This method takes the original input document, and applies the following methods:
First determineSignInput
is called, resulting in a SignInput
object being passed to the digest
method. Then the siganture
is being created using createSignature
with the digest result and last the sign method is using the original data together with the signature. The SignOutput
containing the signed document as well as signature information is being returned.
The result of the above is a SignOutput
which is the original input, but now signed.
Check whether a signature is valid
The default Signature Service implementations delegate this method to the corresponding method of the KeyProvider.
In order to check whether a signature is valid the SignInput is needed. If a reference to that data is not available anymore the determineSignInput
and depending on whether a hash digest was create the digest
method are needed to get back the SignInput object.