Package com.logicaldoc.sign.pdf
Class CreateSignatureBase
- java.lang.Object
-
- com.logicaldoc.sign.pdf.CreateSignatureBase
-
- All Implemented Interfaces:
org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface
- Direct Known Subclasses:
CreateSignature
,CreateVisibleSignature
public abstract class CreateSignatureBase extends Object implements org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface
Common base for signature creators- Since:
- 7.7.2
- Author:
- Marco Meschieri - LogicalDOC
-
-
Constructor Summary
Constructors Constructor Description CreateSignatureBase(File ksFile, String keyStorePassword, String alias, String aliasPassword)
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 int
getMDPPermission(org.apache.pdfbox.pdmodel.PDDocument doc)
Get the access permissions granted for this document in the DocMDP transform parameters dictionary.boolean
isExternalSigning()
void
setCertificateChain(Certificate[] certificateChain)
void
setExternalSigning(boolean externalSigning)
Set if external signing scenario should be used.void
setMDPPermission(org.apache.pdfbox.pdmodel.PDDocument doc, org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature signature, int accessPermissions)
void
setPrivateKey(PrivateKey privateKey)
byte[]
sign(InputStream content)
SignatureInterface implementation.
-
-
-
Constructor Detail
-
CreateSignatureBase
public CreateSignatureBase(File ksFile, String keyStorePassword, String alias, String aliasPassword) throws KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, IOException, CertificateException
Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature.- Parameters:
ksFile
- the java keystore file containing the signing certificatekeyStorePassword
- the password for opening the keystorealias
- the alias of the certificatealiasPassword
- the password to open the alias- 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 Detail
-
setPrivateKey
public final void setPrivateKey(PrivateKey privateKey)
-
setCertificateChain
public final void setCertificateChain(Certificate[] certificateChain)
-
sign
public byte[] sign(InputStream content) throws IOException
SignatureInterface 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.- Specified by:
sign
in interfaceorg.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface
- Parameters:
content
- the content of the file- Throws:
IOException
- cannot write the PDF file
-
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
-true
if external signing should be performed
-
isExternalSigning
public boolean isExternalSigning()
-
getMDPPermission
public int getMDPPermission(org.apache.pdfbox.pdmodel.PDDocument doc)
Get the access permissions granted for this document in the DocMDP transform parameters dictionary. Details are described in the table "Entries in the DocMDP transform parameters dictionary" in the PDF specification.- Parameters:
doc
- document.- Returns:
- the permission value. 0 means no DocMDP transform parameters dictionary exists. Other return values are 1, 2 or 3. 2 is also returned if the DocMDP transform parameters dictionary is found but did not contain a /P entry, or if the value is outside the valid range.
-
setMDPPermission
public void setMDPPermission(org.apache.pdfbox.pdmodel.PDDocument doc, org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature signature, int accessPermissions)
-
-