[
https://issues.apache.org/jira/browse/PDFBOX-1751?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Thomas Chojecki closed PDFBOX-1751.
-----------------------------------
Resolution: Not A Problem
Assignee: Thomas Chojecki
The method signPDF(PDDocument inputDoc ...) malform the document.
inputDoc.save() will rewrite the signed document and broke the signature.
You need to use the method signPDF(byte[] ....) to do it the right way.
Maybe something like this....
public static void main(String[] args) throws Exception
{
String pin = "123456";
File out = new File("tmp/Sample_signed.pdf");
File out2 = new File("tmp/Sample_signed_signed.pdf");
KeyStore keystore = null;
try (InputStream documentIS =
PADESSigner.class.getResourceAsStream("/pdfbox_1751/Sample.pdf");
InputStream keystoreIS =
PADESSigner.class.getResourceAsStream("/pdfbox_1751/Author01.p12");) {
keystore = KeyStore.getInstance("pkcs12");
keystore.load(keystoreIS, pin.toCharArray());
PADESSigner padesSigner = new PADESSigner(keystore, pin);
padesSigner.setSignatureName("Testing");
padesSigner.signPDF(IOUtils.toByteArray(documentIS), out);
}
try (InputStream documentIS = new FileInputStream(out);) {
PADESSigner padesSigner = new PADESSigner(keystore, pin);
padesSigner.setSignatureName("Testing");
padesSigner.signPDF(IOUtils.toByteArray(documentIS), out2);
}
}
> SignDict/Contents illegal data
> ------------------------------
>
> Key: PDFBOX-1751
> URL: https://issues.apache.org/jira/browse/PDFBOX-1751
> Project: PDFBox
> Issue Type: Bug
> Components: Signing
> Affects Versions: 1.8.0
> Environment: Windows 8.1
> Reporter: David KELLER
> Assignee: Thomas Chojecki
> Labels: security, signature
> Attachments: PADESSigner.java
>
>
> 1/ I sign a file using this method
> public static void signByPdfbox(
> File inputPDF,
> File outputPDF,
> KeyStore ks,
> String password)
> throws IOException, UnrecoverableKeyException, KeyStoreException,
> NoSuchAlgorithmException, COSVisitorException, SignatureException {
> PDDocument inputDoc = PDDocument.load(inputPDF);
>
>
> PADESSigner signer = new PADESSigner(ks, password);
>
> signer.setSignatureName("Hello1");
> signer.setSignatureReason("Why noy");
> signer.setSignatureLocation("Curacao");
> signer.setSignatureContactInfo("[email protected]");
>
> signer.signPDF(inputDoc, outputPDF);
> }
> 2/ I resign the same file using the same method and in acrobat reader I have
> this error : SignDict/Contents illegal data
> I have googelized it, and I found only old topics for iText lib.
> I have tried the same with iText 5.X, and double signatures works
--
This message was sent by Atlassian JIRA
(v6.1#6144)