Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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