Top Description Fields Constructors Methods
org.apache.pdfbox.examples.signature

public Class CreateEmbeddedTimeStamp

extends Object
Class Inheritance
Imports
java.io.File, .FileNotFoundException, .FileOutputStream, .IOException, .OutputStream, java.net.URISyntaxException, java.nio.file.Files, java.security.NoSuchAlgorithmException, java.util.Arrays, org.apache.pdfbox.Loader, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature, org.apache.pdfbox.util.Hex, org.bouncycastle.cms.CMSException, .CMSSignedData

An example for timestamp-signing a PDF for PADeS-Specification. The document will only be changed in its existing signature by a signed timestamp (A timestamp and the Hash-Value of the document are signed by a Time Stamp Authority (TSA)). This method only changes the unsigned parameters of a signature, so that it is kept valid. Use case: sign offline to avoid zero-day attacks against the signing machine. Once the signature is there and the pdf is transferred to a network connected machine, one is likely to want to add a timestamp. (Ralf Hauser)
Author
Alexis Suter

Field Summary

Modifier and TypeField and Description
private byte[]
private PDDocument
private PDSignature
private final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
embedNewSignatureIntoDocument(byte[]
byte array of the document
docBytes
,
OutputStream
target, where the file will be written
output
)

Embeds the new signature into the document, by copying the rest of the document

public void
embedTimeStamp(File
the PDF file to sign and to overwrite
file
)

Embeds the given PDF file with signed timestamp(s).

public void
embedTimeStamp(File
The pdf file possibly containing signatures
inFile
,
File
Where the changed document will be saved
outFile
)

Embeds signed timestamp(s) into existing signatures of the given document

public static void
main(String[] args)

private void
processRelevantSignatures(byte[]
byte[] of the input file
documentBytes
)

Create changed Signature with embedded TimeStamp from TSA

private void
processTimeStamping(File
The existing PDF file
inFile
,
File
Where the new file will be written to
outFile
)

Processes the time-stamping of the signature.

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

changedEncodedSignatureback to summary
private byte[] changedEncodedSignature
documentback to summary
private PDDocument document
signatureback to summary
private PDSignature signature
tsaUrlback to summary
private final String tsaUrl

Constructor Detail

CreateEmbeddedTimeStampback to summary
public CreateEmbeddedTimeStamp(String tsaUrl)

Method Detail

embedNewSignatureIntoDocumentback to summary
private void embedNewSignatureIntoDocument(byte[] docBytes, OutputStream output) throws IOException

Embeds the new signature into the document, by copying the rest of the document

Parameters
docBytes:byte[]

byte array of the document

output:OutputStream

target, where the file will be written

embedTimeStampback to summary
public void embedTimeStamp(File file) throws IOException, URISyntaxException

Embeds the given PDF file with signed timestamp(s). Alters the original file on disk.

Parameters
file:File

the PDF file to sign and to overwrite

embedTimeStampback to summary
public void embedTimeStamp(File inFile, File outFile) throws IOException, URISyntaxException

Embeds signed timestamp(s) into existing signatures of the given document

Parameters
inFile:File

The pdf file possibly containing signatures

outFile:File

Where the changed document will be saved

mainback to summary
public static void main(String[] args) throws IOException, URISyntaxException
processRelevantSignaturesback to summary
private void processRelevantSignatures(byte[] documentBytes) throws IOException, CMSException, NoSuchAlgorithmException, URISyntaxException

Create changed Signature with embedded TimeStamp from TSA

Parameters
documentBytes:byte[]

byte[] of the input file

processTimeStampingback to summary
private void processTimeStamping(File inFile, File outFile) throws IOException, URISyntaxException

Processes the time-stamping of the signature.

Parameters
inFile:File

The existing PDF file

outFile:File

Where the new file will be written to

usageback to summary
private static void usage()