java.lang.Objectcom.aspose.words.SignOptions
public class SignOptions
Constructor Summary |
---|
SignOptions()
|
Property Getters/Setters Summary | ||
---|---|---|
java.lang.String | getComments() | |
void | setComments(java.lang.String value) | |
Specifies comments on the digital signature. Default value is empty string. | ||
java.lang.String | getDecryptionPassword() | |
void | setDecryptionPassword(java.lang.String value) | |
The password to decrypt source document. Default value is empty string. | ||
java.util.UUID | getProviderId() | |
void | setProviderId(java.util.UUID value) | |
Specifies the class ID of the signature provider. Default value is Empty (all zeroes) Guid. | ||
java.util.UUID | getSignatureLineId() | |
void | setSignatureLineId(java.util.UUID value) | |
Signature line identifier. Default value is Empty (all zeroes) Guid. | ||
byte[] | getSignatureLineImage() | |
void | setSignatureLineImage(byte[] value) | |
The image that will be shown in associated null .
|
||
java.util.Date | getSignTime() | |
void | setSignTime(java.util.Date value) | |
The date of signing. Default value is current time. |
Constructor Detail |
---|
public SignOptions()
Property Getters/Setters Detail |
---|
getComments/setComments | |
public java.lang.String getComments() / public void setComments(java.lang.String value) |
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() + "Digitally signed.docx"); String outputFileName = getArtifactsDir() + "DigitalSignatureUtil.SignDocument.docx"; SignOptions signOptions = new SignOptions(); signOptions.setComments("Encrypted"); signOptions.setSignTime(new Date()); DigitalSignatureUtil.sign(doc.getOriginalFileName(), outputFileName, certificateHolder, signOptions);
getDecryptionPassword/setDecryptionPassword | |
public java.lang.String getDecryptionPassword() / public void setDecryptionPassword(java.lang.String value) |
Example:
Shows how to sign encrypted document file.// 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 String inputFileName = getMyDir() + "Encrypted.docx"; String outputFileName = getArtifactsDir() + "DigitalSignatureUtil.DecryptionPassword.docx"; DigitalSignatureUtil.sign(inputFileName, outputFileName, certificateHolder, signOptions);
getProviderId/setProviderId | |
public java.util.UUID getProviderId() / public void setProviderId(java.util.UUID value) |
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 signature line.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Date currentDate = new Date(); 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(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx"); SignOptions signOptions = new SignOptions(); signOptions.setSignatureLineId(signatureLine.getId()); signOptions.setProviderId(signatureLine.getProviderId()); signOptions.setComments("Document was signed by vderyushev"); signOptions.setSignTime(currentDate); CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw"); DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx", getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
getSignatureLineId/setSignatureLineId | |
public java.util.UUID getSignatureLineId() / public void setSignatureLineId(java.util.UUID value) |
Example:
Demonstrates how to add new signature line to the document and sign it with personal signature using SignatureLineId.public static void sign() throws Exception { String signPersonName = "Ron Williams"; String srcDocumentPath = getMyDir() + "Document.docx"; String dstDocumentPath = getArtifactsDir() + "SignDocumentCustom.Sign.docx"; String certificatePath = getMyDir() + "morzal.pfx"; String certificatePassword = "aw"; // We need to create simple list with test signers for this example createSignPersonData(); System.out.println("Test data successfully added!"); // Get sign person object by name of the person who must sign a document // This an example, in real use case you would return an object from a database SignPersonTestClass signPersonInfo = gSignPersonList.stream().filter(x -> x.getName() == signPersonName).findFirst().get(); if (signPersonInfo != null) { signDocument(srcDocumentPath, dstDocumentPath, signPersonInfo, certificatePath, certificatePassword); System.out.println("Document successfully signed!"); } else { System.out.println("Sign person does not exist, please check your parameters."); } // Now do something with a signed document, for example, save it to your database // Use 'new Document(dstDocumentPath)' for loading a signed document } /// <summary> /// Signs the document obtained at the source location and saves it to the specified destination. /// </summary> private static void signDocument(final String srcDocumentPath, final String dstDocumentPath, final SignPersonTestClass signPersonInfo, final String certificatePath, final String certificatePassword) throws Exception { // Create new document instance based on a test file that we need to sign Document document = new Document(srcDocumentPath); DocumentBuilder builder = new DocumentBuilder(document); // Add info about responsible person who sign a document SignatureLineOptions signatureLineOptions = new SignatureLineOptions(); signatureLineOptions.setSigner(signPersonInfo.getName()); signatureLineOptions.setSignerTitle(signPersonInfo.getPosition()); // Add signature line for responsible person who sign a document SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine(); signatureLine.setId(signPersonInfo.getPersonId()); // Save a document with line signatures into temporary file for future signing builder.getDocument().save(dstDocumentPath); // Create holder of certificate instance based on your personal certificate // This is the test certificate generated for this example CertificateHolder certificateHolder = CertificateHolder.create(certificatePath, certificatePassword); // Link our signature line with personal signature SignOptions signOptions = new SignOptions(); signOptions.setSignatureLineId(signPersonInfo.getPersonId()); signOptions.setSignatureLineImage(signPersonInfo.getImage()); // Sign a document which contains signature line with personal certificate DigitalSignatureUtil.sign(dstDocumentPath, dstDocumentPath, certificateHolder, signOptions); } /// <summary> /// Create test data that contains info about sing persons. /// </summary> private static void createSignPersonData() throws IOException { InputStream inputStream = new FileInputStream(getImageDir() + "Logo.jpg"); gSignPersonList = new ArrayList<>(); gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Ron Williams", "Chief Executive Officer", DocumentHelper.getBytesFromStream(inputStream))); gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Stephen Morse", "Head of Compliance", DocumentHelper.getBytesFromStream(inputStream))); } private static ArrayList<SignPersonTestClass> gSignPersonList;
getSignatureLineImage/setSignatureLineImage | |
public byte[] getSignatureLineImage() / public void setSignatureLineImage(byte[] value) |
null
.
Example:
Demonstrates how to add new signature line to the document and sign it with personal signature using SignatureLineId.public static void sign() throws Exception { String signPersonName = "Ron Williams"; String srcDocumentPath = getMyDir() + "Document.docx"; String dstDocumentPath = getArtifactsDir() + "SignDocumentCustom.Sign.docx"; String certificatePath = getMyDir() + "morzal.pfx"; String certificatePassword = "aw"; // We need to create simple list with test signers for this example createSignPersonData(); System.out.println("Test data successfully added!"); // Get sign person object by name of the person who must sign a document // This an example, in real use case you would return an object from a database SignPersonTestClass signPersonInfo = gSignPersonList.stream().filter(x -> x.getName() == signPersonName).findFirst().get(); if (signPersonInfo != null) { signDocument(srcDocumentPath, dstDocumentPath, signPersonInfo, certificatePath, certificatePassword); System.out.println("Document successfully signed!"); } else { System.out.println("Sign person does not exist, please check your parameters."); } // Now do something with a signed document, for example, save it to your database // Use 'new Document(dstDocumentPath)' for loading a signed document } /// <summary> /// Signs the document obtained at the source location and saves it to the specified destination. /// </summary> private static void signDocument(final String srcDocumentPath, final String dstDocumentPath, final SignPersonTestClass signPersonInfo, final String certificatePath, final String certificatePassword) throws Exception { // Create new document instance based on a test file that we need to sign Document document = new Document(srcDocumentPath); DocumentBuilder builder = new DocumentBuilder(document); // Add info about responsible person who sign a document SignatureLineOptions signatureLineOptions = new SignatureLineOptions(); signatureLineOptions.setSigner(signPersonInfo.getName()); signatureLineOptions.setSignerTitle(signPersonInfo.getPosition()); // Add signature line for responsible person who sign a document SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine(); signatureLine.setId(signPersonInfo.getPersonId()); // Save a document with line signatures into temporary file for future signing builder.getDocument().save(dstDocumentPath); // Create holder of certificate instance based on your personal certificate // This is the test certificate generated for this example CertificateHolder certificateHolder = CertificateHolder.create(certificatePath, certificatePassword); // Link our signature line with personal signature SignOptions signOptions = new SignOptions(); signOptions.setSignatureLineId(signPersonInfo.getPersonId()); signOptions.setSignatureLineImage(signPersonInfo.getImage()); // Sign a document which contains signature line with personal certificate DigitalSignatureUtil.sign(dstDocumentPath, dstDocumentPath, certificateHolder, signOptions); } /// <summary> /// Create test data that contains info about sing persons. /// </summary> private static void createSignPersonData() throws IOException { InputStream inputStream = new FileInputStream(getImageDir() + "Logo.jpg"); gSignPersonList = new ArrayList<>(); gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Ron Williams", "Chief Executive Officer", DocumentHelper.getBytesFromStream(inputStream))); gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Stephen Morse", "Head of Compliance", DocumentHelper.getBytesFromStream(inputStream))); } private static ArrayList<SignPersonTestClass> gSignPersonList;
getSignTime/setSignTime | |
public java.util.Date getSignTime() / public void setSignTime(java.util.Date value) |
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() + "Digitally signed.docx"); String outputFileName = getArtifactsDir() + "DigitalSignatureUtil.SignDocument.docx"; SignOptions signOptions = new SignOptions(); signOptions.setComments("Encrypted"); signOptions.setSignTime(new Date()); DigitalSignatureUtil.sign(doc.getOriginalFileName(), outputFileName, certificateHolder, signOptions);