Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created February 25, 2021 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/57c273d387e5f608d1d958e21b08c68f to your computer and use it in GitHub Desktop.
Save aspose-com-gists/57c273d387e5f608d1d958e21b08c68f to your computer and use it in GitHub Desktop.
Protect PowerPoint Presentations in Java
// Instantiate a Presentation object that represents a presentation file
Presentation presentation = new Presentation("presentation.pptx");
// Create DigitalSignature object with PFX file and PFX password
DigitalSignature signature = new DigitalSignature("testsignature1.pfx", "testpass1");
// Comment new digital signature
signature.setComments("Aspose.Slides digital signing test.");
// Add digital signature to presentation
presentation.getDigitalSignatures().add(signature);
// Save the PPTX
presentation.save("protected-presentation.pptx", SaveFormat.Pptx);
// Instantiate a Presentation object that represents a presentation file
Presentation presentation = new Presentation("presentation.pptx");
// Protect PPTX with password
presentation.getProtectionManager().encrypt("password");
// Save the PPTX
presentation.save("protected-presentation.pptx", SaveFormat.Pptx);
// Instantiate a Presentation object that represents a presentation file
Presentation presentation = new Presentation("presentation.pptx");
// Check if digital signatures are available
if (presentation.getDigitalSignatures().size() > 0) {
boolean allSignaturesAreValid = true;
// Loop through digital signatures
for (IDigitalSignature signature : presentation.getDigitalSignatures()) {
System.out.println(
signature.getSignTime().toString() + " -- " + (signature.isValid() ? "VALID" : "INVALID"));
allSignaturesAreValid &= signature.isValid();
}
if (allSignaturesAreValid)
System.out.println("Presentation is genuine, all signatures are valid.");
else
System.out.println("Presentation has been modified since signing.");
}
// Save the PPTX
presentation.save("protected-presentation.pptx", SaveFormat.Pptx);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment