Class CreateSignatureBase
- java.lang.Object
-
- org.apache.pdfbox.examples.signature.CreateSignatureBase
-
- All Implemented Interfaces:
SignatureInterface
- Direct Known Subclasses:
CreateSignature,CreateVisibleSignature,CreateVisibleSignature2
public abstract class CreateSignatureBase extends java.lang.Object implements SignatureInterface
-
-
Field Summary
Fields Modifier and Type Field Description private java.security.cert.Certificate[]certificateChainprivate booleanexternalSigningprivate java.security.PrivateKeyprivateKeyprivate java.lang.StringtsaUrl
-
Constructor Summary
Constructors Constructor Description CreateSignatureBase(java.security.KeyStore keystore, char[] pin)Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.security.cert.Certificate[]getCertificateChain()booleanisExternalSigning()voidsetCertificateChain(java.security.cert.Certificate[] certificateChain)voidsetExternalSigning(boolean externalSigning)Set if external signing scenario should be used.voidsetPrivateKey(java.security.PrivateKey privateKey)voidsetTsaUrl(java.lang.String tsaUrl)byte[]sign(java.io.InputStream content)SignatureInterface sample implementation.
-
-
-
Constructor Detail
-
CreateSignatureBase
public CreateSignatureBase(java.security.KeyStore keystore, char[] pin) throws java.security.KeyStoreException, java.security.UnrecoverableKeyException, java.security.NoSuchAlgorithmException, java.io.IOException, java.security.cert.CertificateExceptionInitialize 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:
java.security.KeyStoreException- if the keystore has not been initialized (loaded)java.security.NoSuchAlgorithmException- if the algorithm for recovering the key cannot be foundjava.security.UnrecoverableKeyException- if the given password is wrongjava.security.cert.CertificateException- if the certificate is not valid as signing timejava.io.IOException- if no certificate could be found
-
-
Method Detail
-
setPrivateKey
public final void setPrivateKey(java.security.PrivateKey privateKey)
-
setCertificateChain
public final void setCertificateChain(java.security.cert.Certificate[] certificateChain)
-
getCertificateChain
public java.security.cert.Certificate[] getCertificateChain()
-
setTsaUrl
public void setTsaUrl(java.lang.String tsaUrl)
-
sign
public byte[] sign(java.io.InputStream content) throws java.io.IOExceptionSignatureInterface 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:
java.io.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()
-
-