/** * Extracts a revision from the document. * * @param field the signature field name * @return an InputStream covering the revision. Returns null if it's not a signature field * @throws IOException */ public InputStream extractRevision(String field) throws IOException { getSignatureNames(); if (!sigNames.containsKey(field)) return null; int length = sigNames.get(field)[0]; RandomAccessFileOrArray raf = document.getReader().getSafeFile(); return new RASInputStream(new WindowRandomAccessSource(raf.createSourceView(), 0, length)); }
/** * Extracts a revision from the document. * * @param field the signature field name * @return an InputStream covering the revision. Returns null if it's not a signature field * @throws IOException */ public InputStream extractRevision(String field) throws IOException { getSignatureNames(); if (!sigNames.containsKey(field)) return null; int length = sigNames.get(field)[0]; RandomAccessFileOrArray raf = document.getReader().getSafeFile(); return new RASInputStream(new WindowRandomAccessSource(raf.createSourceView(), 0, length)); }
/** * Checks if the signature covers the entire document (except for signature's Contents) or just a part of it. * * @param name the signature field name * @return true if the signature covers the entire document, false if it doesn't */ public boolean signatureCoversWholeDocument(String name) { getSignatureNames(); if (!sigNames.containsKey(name)) return false; try { ContentsChecker signatureReader = new ContentsChecker(document.getReader().getSafeFile().createSourceView()); return signatureReader.checkWhetherSignatureCoversWholeDocument(acroForm.getField(name)); } catch (IOException e) { throw new PdfException(e); } }
/** * Checks if the signature covers the entire document (except for signature's Contents) or just a part of it. * * @param name the signature field name * @return true if the signature covers the entire document, false if it doesn't */ public boolean signatureCoversWholeDocument(String name) { getSignatureNames(); if (!sigNames.containsKey(name)) return false; try { ContentsChecker signatureReader = new ContentsChecker(document.getReader().getSafeFile().createSourceView()); return signatureReader.checkWhetherSignatureCoversWholeDocument(acroForm.getField(name)); } catch (IOException e) { throw new PdfException(e); } }
private void updateByteRange(PdfPKCS7 pkcs7, PdfSignature signature) { PdfArray b = signature.getByteRange(); RandomAccessFileOrArray rf = document.getReader().getSafeFile(); InputStream rg = null; try { rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(rf.createSourceView(), b.toLongArray())); byte[] buf = new byte[8192]; int rd; while ((rd = rg.read(buf, 0, buf.length)) > 0) { pkcs7.update(buf, 0, rd); } } catch (Exception e) { throw new PdfException(e); } finally { try { if (rg != null) rg.close(); } catch (IOException e) { // this really shouldn't ever happen - the source view we use is based on a Safe view, which is a no-op anyway throw new PdfException(e); } } }
private void updateByteRange(PdfPKCS7 pkcs7, PdfSignature signature) { PdfArray b = signature.getByteRange(); RandomAccessFileOrArray rf = document.getReader().getSafeFile(); InputStream rg = null; try { rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(rf.createSourceView(), b.toLongArray())); byte[] buf = new byte[8192]; int rd; while ((rd = rg.read(buf, 0, buf.length)) > 0) { pkcs7.update(buf, 0, rd); } } catch (Exception e) { throw new PdfException(e); } finally { try { if (rg != null) rg.close(); } catch (IOException e) { // this really shouldn't ever happen - the source view we use is based on a Safe view, which is a no-op anyway throw new PdfException(e); } } }
IRandomAccessSource readerSource = document.getReader().getSafeFile().createSourceView(); InputStream rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(readerSource, gaps)); byte[] signedContent = externalSignatureContainer.sign(rg);
IRandomAccessSource readerSource = document.getReader().getSafeFile().createSourceView(); InputStream rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(readerSource, gaps)); byte[] signedContent = externalSignatureContainer.sign(rg);