Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active March 30, 2021 16:30
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/5c2264d2cc2d4058c5b206630e960570 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/5c2264d2cc2d4058c5b206630e960570 to your computer and use it in GitHub Desktop.
Protect PowerPoint Slides using C++
Protect PowerPoint Slides with Password and Digital Signature using C++
// File paths
const String sourceFilePath = u"SourceDirectory\\SamplePresentation.pptx";
const String signatureFilePath = u"SourceDirectory\\testsignature1.pfx";
const String outputFilePath = u"OutputDirectory\\digital-signature-presentation.pptx";
// Load the presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);
// Create DigitalSignature object with PFX file and password
SharedPtr<DigitalSignature> signature = MakeObject<DigitalSignature>(signatureFilePath, u"testpass1");
// Add comment
signature->set_Comments(u"Test Comments");
// Add digital signature to presentation
presentation->get_DigitalSignatures()->Add(signature);
// Save the presentation
presentation->Save(outputFilePath, SaveFormat::Pptx);
// File paths
const String sourceFilePath = u"SourceDirectory\\SamplePresentation.pptx";
const String outputFilePath = u"OutputDirectory\\protected-presentation.pptx";
// Load the presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);
// Protect presentation with password
presentation->get_ProtectionManager()->Encrypt(u"password");
// Save the presentation
presentation->Save(outputFilePath, SaveFormat::Pptx);
// File path
const String sourceFilePath = u"SourceDirectory\\digital-signature-presentation.pptx";
// Load the presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);
// Check if presentation has digital signatures
if (presentation->get_DigitalSignatures()->get_Count() > 0)
{
bool allSignaturesAreValid = true;
Console::WriteLine(u"Signatures used to sign the presentation: ");
// Verify digital signatures
for (int i = 0; i < presentation->get_DigitalSignatures()->get_Count(); i++)
{
SharedPtr<IDigitalSignature> signature = presentation->get_DigitalSignatures()->idx_get(i);
Console::WriteLine(System::Convert::ToString(signature->get_SignTime()) + u" -- " + (signature->get_IsValid() ? u"VALID" : u"INVALID"));
if (signature->get_IsValid() == false)
{
allSignaturesAreValid = false;
}
}
if (allSignaturesAreValid)
{
Console::WriteLine(u"Presentation is genuine, all signatures are valid.");
}
else
{
Console::WriteLine(u"Presentation has been modified since signing.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment