Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active November 25, 2020 12:44
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/05fc8c9e0b7e8f0635f4e35f71b5bb2e to your computer and use it in GitHub Desktop.
Save aspose-com-gists/05fc8c9e0b7e8f0635f4e35f71b5bb2e to your computer and use it in GitHub Desktop.
Protect PowerPoint PPTX in C#
// Instantiate a Presentation object that represents a presentation file
using (Presentation pres = 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.Comments = "Aspose.Slides digital signing test.";
// Add digital signature to presentation
pres.DigitalSignatures.Add(signature);
// Save presentation
pres.Save("signed-presentation.pptx", Export.SaveFormat.Pptx);
}
// Instantiate a Presentation object that represents a presentation file
using (Presentation pres = new Presentation("presentation.pptx"))
{
// Protect with password
pres.ProtectionManager.Encrypt("password");
// Save presentation
pres.Save("protected-presentation.pptx", Export.SaveFormat.Pptx);
}
// Instantiate a Presentation object that represents a presentation file
using (Presentation pres = new Presentation("presentation.pptx"))
{
// Check if presentation has digital signatures
if (pres.DigitalSignatures.Count > 0)
{
bool allSignaturesAreValid = true;
Console.WriteLine("Signatures used to sign the presentation: ");
// Check if all digital signatures are valid
foreach (DigitalSignature signature in pres.DigitalSignatures)
{
Console.WriteLine(signature.Certificate.SubjectName.Name + ", "
+ signature.SignTime.ToString("yyyy-MM-dd HH:mm") + " -- " + (signature.IsValid ? "VALID" : "INVALID"));
allSignaturesAreValid &= signature.IsValid;
}
if (allSignaturesAreValid)
Console.WriteLine("Presentation is genuine, all signatures are valid.");
else
Console.WriteLine("Presentation has been modified since signing.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment