Class DigestDocument

java.lang.Object
eu.europa.esig.dss.model.CommonDocument
eu.europa.esig.dss.model.DigestDocument
All Implemented Interfaces:
DSSDocument, Serializable

public class DigestDocument extends CommonDocument
Digest representation of a DSSDocument. It can be used to handle a large file to be signed. The computation of the digest associated to the file can be done externally.
See Also:
  • Constructor Details

    • DigestDocument

      public DigestDocument()
      Creates DigestDocument with an empty digest map. Initial algorithm and digest must be specified in order to use the object
    • DigestDocument

      public DigestDocument(Digest digest)
      Creates DigestDocument with an initial Digest
      Parameters:
      digest - Digest for the new DigestDocument
    • DigestDocument

      public DigestDocument(Digest digest, String name)
      Creates DigestDocument with an initial Digest and a specified document name
      Parameters:
      digest - Digest for the new DigestDocument
      name - String name of the document
    • DigestDocument

      public DigestDocument(Digest digest, String name, MimeType mimeType)
      Creates DigestDocument with an initial Digest, a specified name and mimeType of the document
      Parameters:
      digest - Digest for the new DigestDocument
      name - String name of the document
      mimeType - MimeType of the document
    • DigestDocument

      public DigestDocument(DigestAlgorithm digestAlgorithm, byte[] digestValue)
      Creates DigestDocument with a digest provided in a form of byte array
      Parameters:
      digestAlgorithm - DigestAlgorithm
      digestValue - byte array representing the corresponding digest value
    • DigestDocument

      public DigestDocument(DigestAlgorithm digestAlgorithm, String base64EncodeDigest)
      Creates DigestDocument with a digest provided in a form of base64-encoded String
      Parameters:
      digestAlgorithm - DigestAlgorithm
      base64EncodeDigest - the corresponding base 64 encoded digest value
    • DigestDocument

      public DigestDocument(DigestAlgorithm digestAlgorithm, byte[] digestValue, String name)
      Creates DigestDocument with a digest provided in a form of byte array with a specified document name
      Parameters:
      digestAlgorithm - DigestAlgorithm
      digestValue - byte array representing the corresponding digest value
      name - the name of the document
    • DigestDocument

      public DigestDocument(DigestAlgorithm digestAlgorithm, byte[] digestValue, String name, MimeType mimeType)
      Creates DigestDocument with a digest provided in a form of byte array with a specified name and mimeType of the document
      Parameters:
      digestAlgorithm - DigestAlgorithm
      digestValue - byte array representing the corresponding digest value
      name - the name of the document
      mimeType - the mymetype of the document
    • DigestDocument

      public DigestDocument(DigestAlgorithm digestAlgorithm, String base64EncodeDigest, String name)
      Creates DigestDocument with a digest provided in a form of base64-encoded String with a specified document name
      Parameters:
      digestAlgorithm - DigestAlgorithm
      base64EncodeDigest - the corresponding base 64 encoded digest value
      name - the name of the document
    • DigestDocument

      public DigestDocument(DigestAlgorithm digestAlgorithm, String base64EncodeDigest, String name, MimeType mimeType)
      Creates DigestDocument with a digest provided in a form of base64-encoded String with a specified name and mimeType of the document
      Parameters:
      digestAlgorithm - DigestAlgorithm
      base64EncodeDigest - the corresponding base 64 encoded digest value
      name - the name of the document
      mimeType - the mimetype of the document
  • Method Details

    • addDigest

      public void addDigest(Digest digest)
      This method allows to add a Digest with a new digest algorithm to the current DigestDocument. Overwrites the previous digest if the same DigestAlgorithm is provided.
      Parameters:
      digest - Digest for the current document
    • addDigest

      public void addDigest(DigestAlgorithm digestAlgorithm, byte[] digestValue)
      This method allows to add a pair: DigestAlgorithm and the corresponding digest value calculated externally on the encapsulated file.
      Parameters:
      digestAlgorithm - DigestAlgorithm used ot compute the digest value
      digestValue - byte array representing the corresponding digest value
    • addDigest

      public void addDigest(DigestAlgorithm digestAlgorithm, String base64EncodeDigest)
      This method allows to add a pair: DigestAlgorithm and the corresponding digest value calculated externally on the encapsulated file. The digest value is base 64 encoded.
      Parameters:
      digestAlgorithm - DigestAlgorithm
      base64EncodeDigest - the corresponding base 64 encoded digest value
    • getDigestValue

      public byte[] getDigestValue(DigestAlgorithm digestAlgorithm)
      Description copied from interface: DSSDocument
      This method returns digest value of the current document's content using the provided digestAlgorithm
      Specified by:
      getDigestValue in interface DSSDocument
      Overrides:
      getDigestValue in class CommonDocument
      Parameters:
      digestAlgorithm - DigestAlgorithm to get digest for
      Returns:
      byte array representing digest of the document
    • getExistingDigest

      public Digest getExistingDigest()
      Gets the defined digest value for the DigestDocument
      Returns:
      Digest
    • openStream

      public InputStream openStream()
      Description copied from interface: DSSDocument
      Opens a InputStream on the DSSDocument contents. The type of the InputStream depends on the type of the DSSDocument.
      Returns:
      an InputStream
    • save

      public void save(String filePath) throws IOException
      Description copied from interface: DSSDocument
      Save the content of the DSSDocument to the file.
      Specified by:
      save in interface DSSDocument
      Overrides:
      save in class CommonDocument
      Parameters:
      filePath - the path to the file to be created
      Throws:
      IOException - if any IO error happens
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class CommonDocument
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class CommonDocument