Class CreateSignatureBase
java.lang.Object
org.apache.pdfbox.examples.signature.CreateSignatureBase
- All Implemented Interfaces:
SignatureInterface
- Direct Known Subclasses:
CreateSignature,CreateVisibleSignature,CreateVisibleSignature2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Certificate[]private booleanprivate PrivateKeyprivate String -
Constructor Summary
ConstructorsConstructorDescriptionCreateSignatureBase(KeyStore keystore, char[] pin) Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature. -
Method Summary
Modifier and TypeMethodDescriptionbooleanfinal voidsetCertificateChain(Certificate[] certificateChain) voidsetExternalSigning(boolean externalSigning) Set if external signing scenario should be used.final voidsetPrivateKey(PrivateKey privateKey) voidbyte[]sign(InputStream content) SignatureInterface sample implementation.
-
Field Details
-
privateKey
-
certificateChain
-
tsaUrl
-
externalSigning
private boolean externalSigning
-
-
Constructor Details
-
CreateSignatureBase
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- is a pkcs12 keystore.pin- is the pin for the keystore / private key- Throws:
KeyStoreException- if the keystore has not been initialized (loaded)NoSuchAlgorithmException- if the algorithm for recovering the key cannot be foundUnrecoverableKeyException- if the given password is wrongCertificateException- if the certificate is not valid as signing timeIOException- if no certificate could be found
-
-
Method Details
-
setPrivateKey
-
setCertificateChain
-
getCertificateChain
-
setTsaUrl
-
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.
- Specified by:
signin interfaceSignatureInterface- Parameters:
content- is the content as a (Filter)InputStream- Returns:
- signature as a byte array
- Throws:
IOException
-
setExternalSigning
public void setExternalSigning(boolean externalSigning) Set if external signing scenario should be used. Iffalse, SignatureInterface would be used for signing.Default:
false- Parameters:
externalSigning-trueif external signing should be performed
-
isExternalSigning
public boolean isExternalSigning()
-