List of usage examples for com.lowagie.text.pdf PdfName ADBE
PdfName ADBE
To view the source code for com.lowagie.text.pdf PdfName ADBE.
Click Source Link
From source file:eu.europa.ec.markt.dss.signature.pades.PAdESProfileLTV.java
License:Open Source License
@Override public Document extendSignatures(Document document, Document originalData, SignatureParameters parameters) throws IOException { try {/*from www . j a v a 2s. c o m*/ final PdfReader reader = new PdfReader(document.openStream()); final ByteArrayOutputStream output = new ByteArrayOutputStream(); final PdfStamper stamper = new PdfStamper(reader, output, '\0', true); LTVSignatureValidationCallback callback = new LTVSignatureValidationCallback(stamper); pdfSignatureService.validateSignatures(document.openStream(), callback); PdfIndirectReference certsRef = stamper.getWriter().getPdfIndirectReference(); stamper.getWriter().addToBody(callback.getCertsArray(), certsRef, false); PdfDictionary dssDictionary = new PdfDictionary(new PdfName("DSS")); PdfDictionary vriDictionary = new PdfDictionary(new PdfName("VRI")); PdfDictionary sigVriDictionary = new PdfDictionary(); integrateCRL(callback, stamper, dssDictionary, sigVriDictionary, sigVriDictionary); integrateOCSP(callback, stamper, dssDictionary, sigVriDictionary, sigVriDictionary); // Add the signature's VRI dictionary, hashing the signature block from the callback method MessageDigest _md = MessageDigest.getInstance(DigestAlgorithm.SHA1.getName()); String hexHash = Hex.encodeHexString(_md.digest(callback.getSignatureBlock())).toUpperCase(); PdfIndirectReference sigVriRef = stamper.getWriter().getPdfIndirectReference(); stamper.getWriter().addToBody(sigVriDictionary, sigVriRef, false); vriDictionary.put(new PdfName(hexHash), sigVriRef); PdfIndirectReference vriRef = stamper.getWriter().getPdfIndirectReference(); stamper.getWriter().addToBody(vriDictionary, vriRef, false); // Add final objects to DSS dictionary dssDictionary.put(new PdfName("VRI"), vriRef); dssDictionary.put(new PdfName("Certs"), certsRef); PdfIndirectReference dssRef = stamper.getWriter().getPdfIndirectReference(); stamper.getWriter().addToBody(dssDictionary, dssRef, false); reader.getCatalog().put(new PdfName("DSS"), dssRef); // /Extensions<</ADBE<</BaseVersion/1.7/ExtensionLevel 5>>>> PdfDeveloperExtension etsiExtension = new PdfDeveloperExtension(PdfName.ADBE, new PdfName("1.7"), 5); stamper.getWriter().addDeveloperExtension(etsiExtension); stamper.getWriter().addToBody(reader.getCatalog(), reader.getCatalog().getIndRef(), false); stamper.close(); output.close(); Document extendedDocument = new InMemoryDocument(output.toByteArray()); ByteArrayOutputStream ltvDoc = new ByteArrayOutputStream(); ITextPDFDocTimeSampService service = new ITextPDFDocTimeSampService(); byte[] digest = service.digest(extendedDocument.openStream(), parameters); TimeStampResponse tsToken = tspSource.getTimeStampResponse(parameters.getDigestAlgorithm(), digest); service.sign(extendedDocument.openStream(), tsToken.getTimeStampToken().getEncoded(), ltvDoc, parameters); return new InMemoryDocument(ltvDoc.toByteArray()); } catch (DocumentException ex) { throw new RuntimeException(ex); } catch (SignatureException e) { throw new RuntimeException(e); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }