Last active
March 30, 2021 16:30
-
-
Save aspose-com-gists/5c2264d2cc2d4058c5b206630e960570 to your computer and use it in GitHub Desktop.
Protect PowerPoint Slides using 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
Protect PowerPoint Slides with Password and Digital Signature using 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
// 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); |
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
// 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); |
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
// 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