Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public final class PdfSignatureInfo

  1. Object
  2. PdfSignatureInfo

One digital signature found in a PDF, as [#find(byte[])] reads it.

This class checks everything that needs no public-key cryptography: that the signed byte ranges hash to the digest the signature commits to (isDigestValid()), that the certificate is the one the signature names (isCertificateBound()) and that nothing was appended after signing (coversWholeDocument()). The signature itself is verified by PdfSigner.verify on a device, or by the JDK on a server over getSignedAttributes() and getSignatureValue().

Trust is out of scope: a self-signed certificate verifies as well as a CA-issued one. Compare getSignerCertificate() with the certificate you expect, or validate its chain, before believing who signed.

Methods

public static List<PdfSignatureInfo> find(byte[] pdf)Every adbe.pkcs7.detached (or ETSI.CAdES.detached) signature in pdf, in file order.
public long[] getByteRange()The four /ByteRange numbers: offset and length of the bytes signed before the signature, then after it.
public boolean coversWholeDocument()True when the signed ranges reach the end of the file, so nothing was added after signing.
public boolean isDigestValid()True when the signed bytes hash to the digest the signature commits to.
public boolean isCertificateBound()True when the signature’s signingCertificateV2 attribute names the embedded signer certificate, so the certificate cannot have been swapped for another with the same key.
public byte[] getSignedAttributes()The DER signed attributes, the exact bytes the signature is over.
public byte[] getSignatureValue()The raw signature value (DER for ECDSA).
public byte[] getSignerCertificate()The signer’s DER X.509 certificate.
public byte[] getSignerPublicKey()The certificate’s DER SubjectPublicKeyInfo, the key to verify with.
public String getSignerName()The common name of the signer’s certificate, or null.
public String getSignatureAlgorithm()SHA256withRSA or SHA256withECDSA.

Inherited methods

Method details

find

public static List<PdfSignatureInfo> find(byte[] pdf)
Every adbe.pkcs7.detached (or ETSI.CAdES.detached) signature in pdf, in file order. A signature dictionary whose contents cannot be read as a SHA-256 CMS signature is skipped.

getByteRange

public long[] getByteRange()
The four /ByteRange numbers: offset and length of the bytes signed before the signature, then after it.

coversWholeDocument

public boolean coversWholeDocument()
True when the signed ranges reach the end of the file, so nothing was added after signing. An incremental update after the signature (a later annotation, a second signature) makes this false while the signature itself stays valid for the bytes it covers.

isDigestValid

public boolean isDigestValid()
True when the signed bytes hash to the digest the signature commits to. False means the document was changed after it was signed.

isCertificateBound

public boolean isCertificateBound()
True when the signature’s signingCertificateV2 attribute names the embedded signer certificate, so the certificate cannot have been swapped for another with the same key.

getSignedAttributes

public byte[] getSignedAttributes()
The DER signed attributes, the exact bytes the signature is over.

getSignatureValue

public byte[] getSignatureValue()
The raw signature value (DER for ECDSA).

getSignerCertificate

public byte[] getSignerCertificate()
The signer’s DER X.509 certificate.

getSignerPublicKey

public byte[] getSignerPublicKey()
The certificate’s DER SubjectPublicKeyInfo, the key to verify with.

getSignerName

public String getSignerName()
The common name of the signer’s certificate, or null.

getSignatureAlgorithm

public String getSignatureAlgorithm()
SHA256withRSA or SHA256withECDSA.