Last active
November 25, 2020 12:44
-
-
Save aspose-com-gists/05fc8c9e0b7e8f0635f4e35f71b5bb2e to your computer and use it in GitHub Desktop.
Protect PowerPoint PPTX in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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