com.aspose.words

Class DigitalSignatureType

  • java.lang.Object
    • com.aspose.words.DigitalSignatureType
public class DigitalSignatureType 
extends java.lang.Object

Utility class containing constants. Specifies the type of a digital signature.

Example:

Shows how to sign documents with X.509 certificates.
// Verify that a document isn't signed
Assert.assertFalse(FileFormatUtil.detectFileFormat(getMyDir() + "Document.docx").hasDigitalSignature());

// Create a CertificateHolder object from a PKCS #12 file, which we will use to sign the document
CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw", null);

// There are 2 ways of saving a signed copy of a document to the local file system
// 1: Designate unsigned input and signed output files by filename and sign with the passed CertificateHolder
SignOptions signOptions = new SignOptions();
signOptions.setSignTime(new Date());

DigitalSignatureUtil.sign(getMyDir() + "Document.docx", getArtifactsDir() + "Document.DigitalSignature.docx",
        certificateHolder, signOptions);

// 2: Create a stream for the input file and one for the output and create a file, signed with the CertificateHolder, at the file system location determine
InputStream inDoc = new FileInputStream(getMyDir() + "Document.docx");
try {
    OutputStream outDoc = new FileOutputStream(getArtifactsDir() + "Document.DigitalSignature.docx");
    try {
        DigitalSignatureUtil.sign(inDoc, outDoc, certificateHolder);
    } finally {
        if (outDoc != null) outDoc.close();
    }
} finally {
    if (inDoc != null) inDoc.close();
}

Assert.assertTrue(FileFormatUtil.detectFileFormat(getArtifactsDir() + "Document.DigitalSignature.docx").hasDigitalSignature());

// Open the signed document and get its digital signature collection
Document signedDoc = new Document(getArtifactsDir() + "Document.DigitalSignature.docx");
DigitalSignatureCollection digitalSignatureCollection = signedDoc.getDigitalSignatures();

// Verify that all of the document's digital signatures are valid and check their details
Assert.assertTrue(digitalSignatureCollection.isValid());
Assert.assertEquals(1, digitalSignatureCollection.getCount());
Assert.assertEquals(DigitalSignatureType.XML_DSIG, digitalSignatureCollection.get(0).getSignatureType());
Assert.assertEquals("CN=Morzal.Me", signedDoc.getDigitalSignatures().get(0).getIssuerName());
Assert.assertEquals("CN=Morzal.Me", signedDoc.getDigitalSignatures().get(0).getSubjectName());

Field Summary
static final intUNKNOWN = 0
Indicates an error, unknown digital signature type.
static final intCRYPTO_API = 1
The Crypto API signature method used in Microsoft Word 97-2003 .DOC binary documents.
static final intXML_DSIG = 2
The XmlDsig signature method used in OOXML and OpenDocument documents.
 

    • Field Detail

      • UNKNOWN = 0

        public static final int UNKNOWN
        Indicates an error, unknown digital signature type.
      • CRYPTO_API = 1

        public static final int CRYPTO_API
        The Crypto API signature method used in Microsoft Word 97-2003 .DOC binary documents.
      • XML_DSIG = 2

        public static final int XML_DSIG
        The XmlDsig signature method used in OOXML and OpenDocument documents.