public abstract class PdfSignatureInstance
extends java.lang.Object
Constructor and Description |
---|
PdfSignatureInstance() |
Modifier and Type | Method and Description |
---|---|
abstract void |
addArchivalTimestamp(java.lang.String tsaUrl,
java.lang.String username,
java.lang.String password,
PadesLTVParameters params,
java.lang.String newTimestampedFilePath)
Add the validation data contained in params to this document's DSS (document security store) as
defined by PAdES-LTV (PAdES - long term validation).
|
abstract void |
addArchivalTimestamp(java.lang.String tsaUrl,
java.lang.String username,
java.lang.String password,
PadesLTVParameters params,
java.lang.String newTimestampedFilePath,
java.lang.String digestAlgorithm)
Add the validation data contained in params to this document's DSS (document security store) as
defined by PAdES-LTV (PAdES - long term validation).
|
static java.lang.String |
certificateInfosToText(iaik.x509.X509Certificate cert,
java.util.Calendar signDate,
java.lang.String reason,
java.lang.String location)
Create a String of certificate and signature details.
|
abstract void |
certify()
Add a certification signature as defined in initSign.
|
abstract void |
certify(CertificationSignature.ModificationPermission allowedModification)
Add a certification signature as defined in initSign.
|
abstract void |
certify(CertificationSignature.ModificationPermission allowedModification,
LegalContentAttestation attestation)
Add a certification signature as defined in initSign.
|
abstract void |
closeDocument()
Close document instances that may still be open.
|
abstract CertificationSignature |
getCertificationSignature()
Extract the certification signature if included.
|
abstract PadesLTVParameters |
getDocumentSecurityStore()
Get all validation data included in the document security store (dss).
|
abstract PdfSignatureDetails[] |
getSignatures()
Extract all PDF signatures (approval and certification signatures) contained in the document.
|
abstract void |
initSign(java.io.InputStream originalPdf,
byte[] pwd,
java.io.OutputStream signedPdf,
java.security.PrivateKey privateKey,
java.security.cert.Certificate[] certChain,
PdfSignatureParameters params)
Set all details needed to create a PDF signature.
|
abstract void |
initSign(java.lang.String originalFilePath,
byte[] pwd,
java.lang.String signedFilePath,
java.security.PrivateKey privateKey,
java.security.cert.Certificate[] certChain,
PdfSignatureParameters params)
Set all details needed to create a PDF signature.
|
abstract void |
initVerify(java.io.InputStream pdfStream,
byte[] pwd)
Specify the signed PDF document to be further analyzed.
|
abstract void |
initVerify(java.lang.String path,
byte[] pwd)
Specify the signed PDF document to be further analyzed.
|
static void |
setCmsSecurityProvider(iaik.cms.SecurityProvider cmsSecProvider)
Only calls SecurityProvider.setSecurityProvider(cmsSecProvider); to tell IAIK CMS which
provider to use for signing.
|
abstract void |
sign()
Sign the PDF document given as defined in initSign.
|
void |
verify()
Verifies the signature value of each contained signature.
|
public abstract void initSign(java.lang.String originalFilePath, byte[] pwd, java.lang.String signedFilePath, java.security.PrivateKey privateKey, java.security.cert.Certificate[] certChain, PdfSignatureParameters params) throws java.io.IOException, PdfSignatureException
SecurityProvider.setSecurityProvider(new IaikPkcs11SecurityProvider((IAIKPkcs11)pkcs11Provider));
If using EC-keys and the IAIK ECCelerate toolkit, also use the corresponding CMS security
provider: SecurityProvider.setSecurityProvider(new ECCelerateProvider());
originalFilePath
- path to the PDF document, that shall be signedpwd
- password to open the document if encrypted (may be null)signedFilePath
- path where to save the signed PDF documentprivateKey
- private key to use for creating the signaturecertChain
- certificate chain corresponding to the given private keyparams
- parameters defining the required characteristics of the signaturejava.io.IOException
- if the original file can't be read or the signed file can't be writtenPdfSignatureException
- if specified parameters are invalid or certificates can't be parsedpublic abstract void initSign(java.io.InputStream originalPdf, byte[] pwd, java.io.OutputStream signedPdf, java.security.PrivateKey privateKey, java.security.cert.Certificate[] certChain, PdfSignatureParameters params) throws java.io.IOException, PdfSignatureException
SecurityProvider.setSecurityProvider(new IaikPkcs11SecurityProvider((IAIKPkcs11)pkcs11Provider));
If using EC-keys and the IAIK ECCelerate toolkit, also use the corresponding CMS security
provider: SecurityProvider.setSecurityProvider(new ECCelerateProvider());
If using PdfBox the given originalPdf stream will be wrapped in a
NonClosingIteratingInputStream
.originalPdf
- the stream to read the PDF document from, that shall be signedpwd
- password to open the document if encrypted (may be null)signedPdf
- stream to write the signed PDF document toprivateKey
- private key to use for creating the signaturecertChain
- certificate chain corresponding to the given private keyparams
- parameters defining the required characteristics of the signaturejava.io.IOException
- if the original file can't be read or the signed file can't be writtenPdfSignatureException
- if specified parameters are invalid or certificates can't be parsedpublic abstract void sign() throws PdfSignatureException, java.io.IOException
PdfSignatureException
- if errors during signing occurjava.io.IOException
- if the signed document can't be writtenpublic abstract void certify() throws PdfSignatureException, java.io.IOException
PdfSignatureException
- if errors during signing occurjava.io.IOException
- if the signed document can't be writtenCertificationSignature.ModificationPermission
public abstract void certify(CertificationSignature.ModificationPermission allowedModification) throws PdfSignatureException, java.io.IOException
allowedModification
- the modifications allowed in order not to invalidate the signaturePdfSignatureException
- if errors during signing occurjava.io.IOException
- if the signed document can't be writtenCertificationSignature.ModificationPermission
public abstract void certify(CertificationSignature.ModificationPermission allowedModification, LegalContentAttestation attestation) throws PdfSignatureException, java.io.IOException
allowedModification
- the modifications allowed in order not to invalidate the signatureattestation
- legal content attestation certifying the document's contentPdfSignatureException
- if errors during signing occurjava.io.IOException
- if the signed document can't be writtenCertificationSignature.ModificationPermission
public abstract void initVerify(java.lang.String path, byte[] pwd) throws java.io.IOException
path
- path to the signed PDF document that shall be analyzedpwd
- password to open the document if encrypted (may be null)java.io.IOException
- if the document can't be readpublic abstract void initVerify(java.io.InputStream pdfStream, byte[] pwd) throws java.io.IOException
NonClosingIteratingInputStream
.pdfStream
- the stream to read the PDF document that shall be analyzedpwd
- password to open the document if encrypted (may be null)java.io.IOException
- if the stream can't be readpublic abstract PdfSignatureDetails[] getSignatures() throws PdfSignatureException, java.io.IOException
PdfSignatureDetails[] signatures = signatureInstance.getSignatures(); for (int i = 0; i < signatures.length; i++) { PdfSignatureDetails signature = signatures[i]; if (signature instanceof ApprovalSignature) { ((ApprovalSignature) signature).verifySignatureValue(); if (signature instanceof CertificationSignature) { ModificationPermission permissions = ((CertificationSignature) signature) .getModificationPermission(); } } else if (signature instanceof DocumentTimestamp) { PadesLTVParameters ltvParams = ((DocumentTimestamp) signature).getLTVParams(); } }
PdfSignatureException
- if no signed document has been specified with initVerifyjava.io.IOException
- if the document can't be readpublic abstract CertificationSignature getCertificationSignature() throws PdfSignatureException, java.io.IOException
PdfSignatureException
- if more than one certification signature was foundjava.io.IOException
- if the document can't be readpublic void verify() throws PdfSignatureException, java.io.IOException
PdfSignatureException
- if some signatures can't be parsed or are invalidjava.io.IOException
- if the document or the signatures can't be readgetSignatures()
public abstract PadesLTVParameters getDocumentSecurityStore() throws PdfSignatureException, java.io.IOException
PdfSignatureException
- if some dss data can't be parsedjava.io.IOException
- if some dss data can't be readpublic abstract void addArchivalTimestamp(java.lang.String tsaUrl, java.lang.String username, java.lang.String password, PadesLTVParameters params, java.lang.String newTimestampedFilePath) throws PdfSignatureException, iaik.tsp.TspVerificationException, java.io.IOException
tsaUrl
- URL of the timestamp authorityusername
- username for authorizationpassword
- password for authorizationparams
- parameters including the validation data to be addednewTimestampedFilePath
- the file path where the new document containing the data and timestamp shall be savedPdfSignatureException
- if the validation data can't be encoded or the timestamp can't be creatediaik.tsp.TspVerificationException
- if errors occur when requesting and verifying the timestampjava.io.IOException
- if the validation data or the document timestamp can't be writtenpublic abstract void addArchivalTimestamp(java.lang.String tsaUrl, java.lang.String username, java.lang.String password, PadesLTVParameters params, java.lang.String newTimestampedFilePath, java.lang.String digestAlgorithm) throws PdfSignatureException, iaik.tsp.TspVerificationException, java.io.IOException
tsaUrl
- URL of the timestamp authorityusername
- username for authorizationpassword
- password for authorizationparams
- parameters including the validation data to be addednewTimestampedFilePath
- the file path where the new document containing the data and timestamp shall be saveddigestAlgorithm
- digest algorithm used to digest the timestamped data (timestamp imprint)PdfSignatureException
- if the validation data can't be encoded or the timestamp can't be creatediaik.tsp.TspVerificationException
- if errors occur when requesting and verifying the timestampjava.io.IOException
- if the validation data or the document timestamp can't be writtenpublic abstract void closeDocument()
public static void setCmsSecurityProvider(iaik.cms.SecurityProvider cmsSecProvider)
cmsSecProvider
- the security provider to usepublic static java.lang.String certificateInfosToText(iaik.x509.X509Certificate cert, java.util.Calendar signDate, java.lang.String reason, java.lang.String location)
cert
- certificate of the signersignDate
- date of signaturereason
- reason for signaturelocation
- location of signature