java.lang.Object
com.aspose.words.DigitalSignatureUtil
public abstract class DigitalSignatureUtil
Since digital signature works with file content rather than Document Object Model these methods are put into a separate class. Supported formats are Example:
// By string:
Document doc = new Document(getMyDir() + "Document.DigitalSignature.docx");
String outFileName = getMyDir() + "\\Artifacts\\Document.NoSignatures.FromString.docx";
DigitalSignatureUtil.removeAllSignatures(doc.getOriginalFileName(), outFileName);
// By stream:
FileInputStream streamIn = new FileInputStream(getMyDir() + "Document.DigitalSignature.docx");
FileOutputStream streamOut = new FileOutputStream(getMyDir() + "\\Artifacts\\Document.NoSignatures.FromInputStream.doc");
DigitalSignatureUtil.removeAllSignatures(streamIn, streamOut);
| Method Summary | ||
|---|---|---|
static DigitalSignatureCollection | loadSignatures(java.lang.String fileName) | |
| Loads digital signatures from document. | ||
static void | removeAllSignatures(java.lang.String srcFileName, java.lang.String dstFileName) | |
| Removes all digital signatures from source file and writes unsigned file to destination file. | ||
static void | sign(java.lang.String srcFileName, java.lang.String dstFileName, CertificateHolder certHolder) | |
|
Signs source document using given Document should be either |
||
static void | sign(java.lang.String srcFileName, java.lang.String dstFileName, CertificateHolder certHolder, SignOptions signOptions) | |
|
Signs source document using given Document should be either |
||
| Method Detail |
|---|
loadSignatures | |
public static DigitalSignatureCollection loadSignatures(java.lang.String fileName) throws java.lang.Exception | |
fileName - Path to the document.Example:
Shows how to load all existing signatures from a document.// By string: DigitalSignatureCollection digitalSignatures = DigitalSignatureUtil.loadSignatures(getMyDir() + "Document.DigitalSignature.docx"); // By stream: InputStream stream = new FileInputStream(getMyDir() + "Document.DigitalSignature.docx"); digitalSignatures = DigitalSignatureUtil.loadSignatures(stream);
removeAllSignatures | |
public static void removeAllSignatures(java.lang.String srcFileName, java.lang.String dstFileName)
throws java.lang.Exception | |
Example:
Shows how to remove every signature from a document.// By string: Document doc = new Document(getMyDir() + "Document.DigitalSignature.docx"); String outFileName = getMyDir() + "\\Artifacts\\Document.NoSignatures.FromString.docx"; DigitalSignatureUtil.removeAllSignatures(doc.getOriginalFileName(), outFileName); // By stream: FileInputStream streamIn = new FileInputStream(getMyDir() + "Document.DigitalSignature.docx"); FileOutputStream streamOut = new FileOutputStream(getMyDir() + "\\Artifacts\\Document.NoSignatures.FromInputStream.doc"); DigitalSignatureUtil.removeAllSignatures(streamIn, streamOut);
sign | |
public static void sign(java.lang.String srcFileName, java.lang.String dstFileName, CertificateHolder certHolder) throws java.lang.Exception | |
Document should be either
srcFileName - The file name of the document to sign.dstFileName - The file name of the signed document output.certHolder - sign | |
public static void sign(java.lang.String srcFileName, java.lang.String dstFileName, CertificateHolder certHolder, SignOptions signOptions) throws java.lang.Exception | |
Document should be either
srcFileName - The file name of the document to sign.dstFileName - The file name of the signed document output.certHolder - signOptions - 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);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);