com.aspose.words

Class SignOptions

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

Allows to specify options for document signing.

Constructor Summary
 
Property Getters/Setters Summary
java.lang.StringgetComments()
void
setComments(java.lang.Stringvalue)
           Specifies comments on the digital signature. Default value is empty string.
java.lang.StringgetDecryptionPassword()
void
setDecryptionPassword(java.lang.Stringvalue)
           The password to decrypt source document. Default value is empty string.
java.util.UUIDgetProviderId()
void
setProviderId(java.util.UUIDvalue)
           Specifies the class ID of the signature provider. Default value is Empty (all zeroes) Guid.
java.util.UUIDgetSignatureLineId()
void
setSignatureLineId(java.util.UUIDvalue)
           Signature line identifier. Default value is Empty (all zeroes) Guid.
byte[]getSignatureLineImage()
void
           The image that will be shown in associated SignatureLine. Default value is null.
java.util.DategetSignTime()
void
setSignTime(java.util.Datevalue)
           The date of signing. Default value is current time.
 

    • Constructor Detail

      • SignOptions

        public SignOptions()
    • Property Getters/Setters Detail

      • getComments/setComments

        public java.lang.String getComments() / public void setComments(java.lang.String value)
        
        Specifies comments on the digital signature. Default value is empty string.

        Example:

        Shows how to sign documents using certificate holder and sign options.
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        // By string:
        Document doc = new Document(getMyDir() + "Document.DigitalSignature.docx");
        String outputFileName = getMyDir() + "\\Artifacts\\Document.DigitalSignature.docx";
        
        SignOptions signOptions = new SignOptions();
        signOptions.setComments("My comment");
        signOptions.setSignTime(new Date());
        
        DigitalSignatureUtil.sign(doc.getOriginalFileName(), outputFileName, certificateHolder, signOptions);
        
        // By stream:
        InputStream streamIn = new FileInputStream(getMyDir() + "Document.DigitalSignature.docx");
        OutputStream streamOut = new FileOutputStream(getMyDir() + "\\Artifacts\\Document.DigitalSignature.docx");
        
        DigitalSignatureUtil.sign(streamIn, streamOut, certificateHolder, signOptions);
      • getDecryptionPassword/setDecryptionPassword

        public java.lang.String getDecryptionPassword() / public void setDecryptionPassword(java.lang.String value)
        
        The password to decrypt source document. Default value is empty string. If OOXML document is encrypted, you should provide decryption password to decrypt source document before it will be signed. This is not required for documents in binary DOC format.

        Example:

        Shows how to sign encrypted document opened from a file.
        String outputFileName = getMyDir() + "\\Artifacts\\Document.Encrypted.docx";
        
        Document doc = new Document(getMyDir() + "Document.Encrypted.docx", new LoadOptions("docPassword"));
        
        // Create certificate holder from a file.
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        SignOptions signOptions = new SignOptions();
        signOptions.setComments("Comment");
        signOptions.setSignTime(new Date());
        signOptions.setDecryptionPassword("docPassword");
        
        // Digitally sign encrypted with "docPassword" document in the specified path.
        DigitalSignatureUtil.sign(doc.getOriginalFileName(), outputFileName, certificateHolder, signOptions);
      • getProviderId/setProviderId

        public java.util.UUID getProviderId() / public void setProviderId(java.util.UUID value)
        
        Specifies the class ID of the signature provider. Default value is Empty (all zeroes) Guid.

        The cryptographic service provider (CSP) is an independent software module that actually performs cryptography algorithms for authentication, encoding, and encryption. MS Office reserves the value of {00000000-0000-0000-0000-000000000000} for its default signature provider.

        The GUID of the additionally installed provider should be obtained from the documentation shipped with the provider.

        In addition, all the installed cryptographic providers are enumerated in windows registry. It can be found in the following path: HKLM\SOFTWARE\Microsoft\Cryptography\Defaults\Provider. There is a key name "CP Service UUID" which corresponds to a GUID of signature provider.

        Example:

        Shows how to sign document with personal certificate and specific signatire line.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
        signatureLineOptions.setSigner("vderyushev");
        signatureLineOptions.setSignerTitle("QA");
        signatureLineOptions.setEmail("vderyushev@aspose.com");
        signatureLineOptions.setShowDate(true);
        signatureLineOptions.setDefaultInstructions(false);
        signatureLineOptions.setInstructions("You need more info about signature line");
        signatureLineOptions.setAllowComments(true);
        
        SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
        signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.SignatureLineProviderId In.docx");
        
        SignOptions signOptions = new SignOptions();
        signOptions.setSignatureLineId(signatureLine.getId());
        signOptions.setProviderId(signatureLine.getProviderId());
        signOptions.setComments("Document was signed by vderyushev");
        signOptions.setSignTime(new Date());
        
        CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        DigitalSignatureUtil.sign(getMyDir() + "\\Artifacts\\DocumentBuilder.SignatureLineProviderId In.docx", getMyDir() + "\\Artifacts\\DocumentBuilder.SignatureLineProviderId Out.docx", certHolder, signOptions);
      • getSignatureLineId/setSignatureLineId

        public java.util.UUID getSignatureLineId() / public void setSignatureLineId(java.util.UUID value)
        
        Signature line identifier. Default value is Empty (all zeroes) Guid. When set, it associates SignatureLine with corresponding DigitalSignature.

        Example:

        Shows how to sign document with personal certificate and specific signatire line.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
        signatureLineOptions.setSigner("vderyushev");
        signatureLineOptions.setSignerTitle("QA");
        signatureLineOptions.setEmail("vderyushev@aspose.com");
        signatureLineOptions.setShowDate(true);
        signatureLineOptions.setDefaultInstructions(false);
        signatureLineOptions.setInstructions("You need more info about signature line");
        signatureLineOptions.setAllowComments(true);
        
        SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
        signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.SignatureLineProviderId In.docx");
        
        SignOptions signOptions = new SignOptions();
        signOptions.setSignatureLineId(signatureLine.getId());
        signOptions.setProviderId(signatureLine.getProviderId());
        signOptions.setComments("Document was signed by vderyushev");
        signOptions.setSignTime(new Date());
        
        CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        DigitalSignatureUtil.sign(getMyDir() + "\\Artifacts\\DocumentBuilder.SignatureLineProviderId In.docx", getMyDir() + "\\Artifacts\\DocumentBuilder.SignatureLineProviderId Out.docx", certHolder, signOptions);
      • getSignatureLineImage/setSignatureLineImage

        public byte[] getSignatureLineImage() / public void setSignatureLineImage(byte[] value)
        
        The image that will be shown in associated SignatureLine. Default value is null.
      • getSignTime/setSignTime

        public java.util.Date getSignTime() / public void setSignTime(java.util.Date value)
        
        The date of signing. Default value is current time.

        Example:

        Shows how to sign documents using certificate holder and sign options.
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        // By string:
        Document doc = new Document(getMyDir() + "Document.DigitalSignature.docx");
        String outputFileName = getMyDir() + "\\Artifacts\\Document.DigitalSignature.docx";
        
        SignOptions signOptions = new SignOptions();
        signOptions.setComments("My comment");
        signOptions.setSignTime(new Date());
        
        DigitalSignatureUtil.sign(doc.getOriginalFileName(), outputFileName, certificateHolder, signOptions);
        
        // By stream:
        InputStream streamIn = new FileInputStream(getMyDir() + "Document.DigitalSignature.docx");
        OutputStream streamOut = new FileOutputStream(getMyDir() + "\\Artifacts\\Document.DigitalSignature.docx");
        
        DigitalSignatureUtil.sign(streamIn, streamOut, certificateHolder, signOptions);