/** * Will return the embedded signature between the byterange gap. * * @param pdfFile The signed pdf file as InputStream * @return a byte array containing the signature * @throws IOException if the pdfFile can't be read */ public byte[] getContents(InputStream pdfFile) throws IOException { int[] byteRange = getByteRange(); int begin = byteRange[0]+byteRange[1]+1; int len = byteRange[2]-begin; return getContents(new COSFilterInputStream(pdfFile,new int[] {begin,len})); }
@Override public int read(byte[] b) throws IOException { return read(b,0,b.length); }
/** * Return the signed content of the document. This is not a PDF file, nor is it the PDF file * before signing, it is the byte sequence made of the input minus the area where the signature * bytes will be. See "The ByteRange and signature value" in the document * <a href="https://www.adobe.com/devnet-docs/acrobatetk/tools/DigSig/Acrobat_DigitalSignatures_in_PDF.pdf#page=5">Digital * Signatures in a PDF</a>. * * @param pdfFile The signed pdf file as InputStream * @return a byte array containing only the signed part of the content * @throws IOException if the pdfFile can't be read */ public byte[] getSignedContent(InputStream pdfFile) throws IOException { try (COSFilterInputStream fis = new COSFilterInputStream(pdfFile, getByteRange())) { return fis.toByteArray(); } }
/** * Reads the visual signature from the given visual signature properties * * @param visSignatureProperties the <code>PDVisibleSigProperties</code> object containing the * visual signature * * @throws IOException when something went wrong during parsing */ public void setVisualSignature(PDVisibleSigProperties visSignatureProperties) throws IOException { setVisualSignature(visSignatureProperties.getVisibleSignature()); }
/** * * @return true if the Filter is required */ public boolean isFilterRequired() { return getCOSObject().getFlag( COSName.FF, FLAG_FILTER); }
/** * set true if URL shall be required as a constraint on signature. * * @param flag if true, the specified URL shall be enforced as a constraint. */ public void setURLRequired(boolean flag) { this.getCOSObject().setFlag(COSName.FF, FLAG_URL, flag); }
private void nextAvailable() throws IOException { while (!inRange()) { ++position; if(super.read()<0) { break; } } }
/** * Reads the visual signature from the given input stream. * * @param is the input stream containing the visual signature * @throws IOException when something went wrong during parsing */ public void setVisualSignature(InputStream is) throws IOException { initFromRandomAccessRead(new RandomAccessBuffer(is)); }
/** * Will return the embedded signature between the byterange gap. * * @param pdfFile The signed pdf file as byte array * @return a byte array containing the signature * @throws IOException if the pdfFile can't be read */ public byte[] getContents(byte[] pdfFile) throws IOException { int[] byteRange = getByteRange(); int begin = byteRange[0]+byteRange[1]+1; int len = byteRange[2]-begin; return getContents(new COSFilterInputStream(pdfFile,new int[] {begin,len})); }
/** * Return the signed content of the document. This is not a PDF file, nor is it the PDF file * before signing, it is the byte sequence made of the input minus the area where the signature * bytes will be. See "The ByteRange and signature value" in the document * <a href="https://www.adobe.com/devnet-docs/acrobatetk/tools/DigSig/Acrobat_DigitalSignatures_in_PDF.pdf#page=5">Digital * Signatures in a PDF</a>. * * @param pdfFile The signed pdf file as byte array * @return a byte array containing only the signed part of the content * @throws IOException if the pdfFile can't be read */ public byte[] getSignedContent(byte[] pdfFile) throws IOException { try (COSFilterInputStream fis = new COSFilterInputStream(pdfFile, getByteRange())) { return fis.toByteArray(); } }
/** * * @return true if the SubFilter is required */ public boolean isSubFilterRequired() { return getCOSObject().getFlag( COSName.FF, FLAG_SUBFILTER); }
/** * * @return true if the Subject is required */ public boolean isSubjectRequired() { return this.getCOSObject().getFlag(COSName.FF, FLAG_SUBJECT); }
/** * set true if the Reason shall be required. * * @param flag if true, the Reason entry shall be used. */ public void setReasonRequired(boolean flag) { getCOSObject().setFlag( COSName.FF, FLAG_REASON, flag); }
/** * set true if subject shall be required as a constraint on signature. * * @param flag if true, the specified Subject shall be enforced as a constraint. */ public void setSubjectRequired(boolean flag) { this.getCOSObject().setFlag(COSName.FF, FLAG_SUBJECT, flag); }
/** * * @return true if the LegalAttestation is required */ public boolean isLegalAttestationRequired() { return getCOSObject().getFlag( COSName.FF, FLAG_LEGAL_ATTESTATION); }
/** * set true if Issuer shall be required as a constraint on signature. * * @param flag if true, the specified Issuer shall be enforced as a constraint. */ public void setIssuerRequired(boolean flag) { this.getCOSObject().setFlag(COSName.FF, FLAG_ISSUER, flag); }
/** * set true if the V entry shall be required. * * @param flag if true, the V entry shall be used. */ public void setVRequired(boolean flag) { getCOSObject().setFlag( COSName.FF, FLAG_V, flag); }
/** * * @return true if the URL is required */ public boolean isURLRequired() { return this.getCOSObject().getFlag(COSName.FF, FLAG_URL); }
/** * * @return true if the Reason is required */ public boolean isReasonRequired() { return getCOSObject().getFlag( COSName.FF, FLAG_REASON); }
/** * set true if the AddRevInfo shall be required. * * @param flag if true, the AddRevInfo shall be used. */ public void setAddRevInfoRequired(boolean flag) { getCOSObject().setFlag( COSName.FF, FLAG_ADD_REV_INFO, flag); }