Digital Signature in PowerPoint
Digital certificate is used to create a password protected powerpoint presentation, marked as created by a particular organization or person. Digital certificate can be obtained by contacting an authorized organization - a certificate authority. After installing digital certificate into the system, it can be used to add a digital signature to the presentation via File -> Info -> Protect Presentation:
Presentation may contain more than one digital signatures. After the digital signature is added to the presentation, a special message will appear in the PowerPoint:
To sign presentation or check the authenticity of presentation signatures, Aspose.Slides API provides DigitalSignature class, DigitalSignatureCollection class and Presentation.getDigitalSignatures method. Currently, digital signatures are supported for PPTX format only.
Add Digital Signature from PFX Certificate
The code sample below demonstrates how to add digital signature from a PFX certificate:
- Open PFX file and pass PFX password to DigitalSignature object.
- Add created signature to the presentation object.
// Opening the presentation file
var pres = new aspose.slides.Presentation();
try {
// Create DigitalSignature object with PFX file and PFX password
var signature = new aspose.slides.DigitalSignature("testsignature1.pfx", "testpass1");
// Comment new digital signature
signature.setComments("Aspose.Slides digital signing test.");
// Add digital signature to presentation
pres.getDigitalSignatures().add(signature);
// Save presentation
pres.save("SomePresentationSigned.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
pres.dispose();
}
Now its possible to check if the presentation was digitally signed and has not been modified:
// Open presentation
var pres = new aspose.slides.Presentation("SomePresentationSigned.pptx");
try {
if (pres.getDigitalSignatures().size() > 0) {
var allSignaturesAreValid = true;
console.log("Signatures used to sign the presentation: ");
// Check if all digital signatures are valid
for (let i = 0; i < pres.getDigitalSignatures().size(); i++) {
let signature = pres.getDigitalSignatures().get_Item(i);
console.log((((signature.getComments() + ", ") + signature.getSignTime().toString()) + " -- ") + (signature.isValid() ? "VALID" : "INVALID"));
allSignaturesAreValid &= signature.isValid();
}
if (allSignaturesAreValid) {
console.log("Presentation is genuine, all signatures are valid.");
} else {
console.log("Presentation has been modified since signing.");
}
}
} finally {
if (pres != null) {
pres.dispose();
}
}