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

public abstract Class CreateSignatureBase

extends Object
implements SignatureInterface
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface
Known Direct Subclasses
org.apache.pdfbox.examples.signature.CreateVisibleSignature, org.apache.pdfbox.examples.signature.CreateVisibleSignature2, org.apache.pdfbox.examples.signature.CreateSignature
Imports
java.io.IOException, .InputStream, java.net.URISyntaxException, java.security.GeneralSecurityException, .KeyStore, .KeyStoreException, .NoSuchAlgorithmException, .PrivateKey, .UnrecoverableKeyException, java.security.cert.Certificate, .CertificateException, .X509Certificate, java.util.Arrays, .Enumeration, org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface, org.bouncycastle.cert.jcajce.JcaCertStore, org.bouncycastle.cms.CMSException, .CMSSignedData, .CMSSignedDataGenerator, org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder, org.bouncycastle.operator.ContentSigner, .OperatorCreationException, org.bouncycastle.operator.jcajce.JcaContentSignerBuilder, .JcaDigestCalculatorProviderBuilder

Field Summary

Modifier and TypeField and Description
private Certificate[]
private boolean
private PrivateKey
private String

Constructor Summary

AccessConstructor and Description
public
CreateSignatureBase(KeyStore
is a pkcs12 keystore.
keystore
,
char[]
is the pin for the keystore / private key
pin
)

Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature.

Method Summary

Modifier and TypeMethod and Description
public Certificate[]
public boolean
public final void
setCertificateChain(final Certificate[] certificateChain)

public void
setExternalSigning(boolean
true if external signing should be performed
externalSigning
)

Set if external signing scenario should be used.

public final void
public void
setTsaUrl(String tsaUrl)

public byte[]
sign(InputStream
is the content as a (Filter)InputStream
content
)

Implements org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface.sign.

SignatureInterface sample implementation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

certificateChainback to summary
private Certificate[] certificateChain
externalSigningback to summary
private boolean externalSigning
privateKeyback to summary
private PrivateKey privateKey
tsaUrlback to summary
private String tsaUrl

Constructor Detail

CreateSignatureBaseback to summary
public CreateSignatureBase(KeyStore keystore, char[] pin) throws KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, IOException, CertificateException

Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature.

Parameters
keystore:KeyStore

is a pkcs12 keystore.

pin:char[]

is the pin for the keystore / private key

Exceptions
KeyStoreException:
if the keystore has not been initialized (loaded)
UnrecoverableKeyException:
if the given password is wrong
NoSuchAlgorithmException:
if the algorithm for recovering the key cannot be found
IOException:
if no certificate could be found
CertificateException:
if the certificate is not valid as signing time

Method Detail

getCertificateChainback to summary
public Certificate[] getCertificateChain()
isExternalSigningback to summary
public boolean isExternalSigning()
setCertificateChainback to summary
public final void setCertificateChain(final Certificate[] certificateChain)
setExternalSigningback to summary
public void setExternalSigning(boolean externalSigning)

Set if external signing scenario should be used. If false, SignatureInterface would be used for signing.

Default: false

Parameters
externalSigning:boolean

true if external signing should be performed

setPrivateKeyback to summary
public final void setPrivateKey(PrivateKey privateKey)
setTsaUrlback to summary
public void setTsaUrl(String tsaUrl)
signback to summary
public byte[] sign(InputStream content) throws IOException

Implements org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface.sign.

SignatureInterface sample implementation.

This method will be called from inside of the pdfbox and create the PKCS #7 signature. The given InputStream contains the bytes that are given by the byte range.

This method is for internal use only.

Use your favorite cryptographic library to implement PKCS #7 signature creation. If you want to create the hash and the signature separately (e.g. to transfer only the hash to an external application), read this answer or this answer.

Parameters
content:InputStream

Doc from org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface.sign.

is the content as a (Filter)InputStream

Returns:byte[]

Doc from org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface.sign.

signature as a byte array

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface.sign.

if the signature could not be created