/** * Gets the document bytes that are hashable when using external signatures. * The general sequence is: * {@link #preClose(Map)}, {@link #getRangeStream()} and {@link #close(PdfDictionary)}. * * @return The {@link InputStream} of bytes to be signed. */ protected InputStream getRangeStream() throws IOException { RandomAccessSourceFactory fac = new RandomAccessSourceFactory(); return new RASInputStream(fac.createRanged(getUnderlyingSource(), range)); }
/** * Gets the document bytes that are hashable when using external signatures. * The general sequence is: * {@link #preClose(Map)}, {@link #getRangeStream()} and {@link #close(PdfDictionary)}. * * @return The {@link InputStream} of bytes to be signed. */ protected InputStream getRangeStream() throws IOException { RandomAccessSourceFactory fac = new RandomAccessSourceFactory(); return new RASInputStream(fac.createRanged(getUnderlyingSource(), range)); }
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); } } }
InputStream rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(readerSource, gaps)); byte[] signedContent = externalSignatureContainer.sign(rg); int spaceAvailable = (int) (gaps[2] - gaps[1]) - 2;
InputStream rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(readerSource, gaps)); byte[] signedContent = externalSignatureContainer.sign(rg); int spaceAvailable = (int) (gaps[2] - gaps[1]) - 2;