Microsoft Information Protection SDK – Begrepp för skyddshanterare
I MIP Protection SDK mip::ProtectionHandler
exponerar funktionerna för kryptering och dekryptering av skyddade strömmar och buffertar, utför åtkomstkontroller, hämtar publiceringslicensen och hämtar attribut från den skyddade informationen.
Behov
För att skapa en ProtectionHandler
för att arbeta med en specifik fil krävs följande:
- En
mip::MipContext
- En
mip::ProtectionProfile
- En
mip::ProtectionEngine
som har lagts till iProtectionProfile
- En klass som ärver
mip::ProtectionHandler::Observer
. - En
mip::ProtectionDescriptor
licens för eller publicering
Skapa en skyddshanterare
mip::ProtectionHandler
objekt skapas för antingen skydds- eller förbrukningsåtgärder . Hanteraren skapas med någon av fyra funktioner, beroende på scenariot.
mip::ProtectionEngine->CreateProtectionHandlerForConsumptionAsync()
mip::ProtectionEngine->CreateProtectionHandlerForConsumption()
mip::ProtectionEngine->CreateProtectionHandlerForPublishingAsync()
mip::ProtectionEngine->CreateProtectionHandlerForPublishing()
Dessa funktioner accepterar antingen ett objekt eller mip::ProtectionHandler::ConsumptionSettings
ett mip::ProtectionHandler::PublishingSettings
objekt.
Skapa en publiceringshanterare
Det krävs tre steg för att skapa en publiceringshanterare:
- Skapa ett
mip::ProtectionDescriptor
objekt. mip::ProtectionDescriptor
Använd för att instansieramip::ProtectionHandler::PublishingSettings
.- Anropa
mip::ProtectionEngine::CreateProtectionHandlerForPublishingAsync()
att skicka in objektet, observatörenPublishingSettings
och löftet.
Skapa från beskrivning
Om du skyddar innehåll som ännu inte har skyddats eller när du tillämpar nytt skydd på innehåll, vilket innebär att det har dekrypterats, måste en mip::ProtectionDescriptor
konstrueras. När objektet har skapats används det för att instansiera objektet mip::ProtectionHandler::PublishingSettings()
. Resultatet returneras via mip::ProtectionHandler::Observer
.
// Create the protection descriptor, passing in a templateId.
auto descriptorBuilder = mip::ProtectionDescriptorBuilder::CreateFromTemplate(protectionOptions.templateId);
std::shared_ptr<mip::ProtectionDescriptor> descriptor = descriptorBuilder->Build();
// Define the handler promise, future, and observer.
auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<ProtectionHandler>>>();
auto handlerFuture = handlerPromise->get_future();
auto handlerObserver = std::make_shared<ProtectionHandlerObserverImpl>();
// Create the PublishingSettings object using the previously-created descriptor as input.
mip::ProtectionHandler::PublishingSettings publishingSettings = mip::ProtectionHandler::PublishingSettings(descriptor);
// Create/get the publishing handler from the publishing settings, observer, and promise.
mEngine->CreateProtectionHandlerForPublishingAsync(publishingSettings, handlerObserver, handlerPromise);
auto handler = handlerFuture.get();
return handler;
När du har skapat ProtectionHandler
objektet kan skyddsåtgärder (kryptera/dekryptera) utföras. Publiceringslicensen måste hämtas från hanteraren och lagras med det krypterade innehållet. Publiceringslicensen kan hämtas genom att anropa: handler->GetSerializedPublishingLicense();
Skyddat innehåll utan motsvarande publiceringslicens kan inte dekrypteras.
Skapa förbrukningshanteraren
Det krävs tre steg för att skapa en publiceringshanterare:
- Extrahera en serialiserad publiceringslicens
std::vector<uint8_t>
från det skyddade innehållet. - Använd den serialiserade publiceringslicensen för att instansiera
mip::ProtectionHandler::ConsumptionSettings
. - Anropa
mip::ProtectionEngine::CreateProtectionHandlerForConsumptionAsync()
att skicka in objektet, observatörenConsumptionSettings
och löftet.
Det här exemplet förutsätter att publiceringslicensen redan har lästs från någon källa och lagrats i std::vector<uint8_t> serializedPublishingLicense
.
//TODO: Implement GetPublishingLicense()
//Snip implies that function reads PL from source file, database, stream, etc.
std::vector<uint8_t> serializedPublishingLicense = GetPublishingLicense(filePath);
// Define the handler promise, future, and observer.
auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<ProtectionHandler>>>();
auto handlerFuture = handlerPromise->get_future();
shared_ptr<ProtectionHandlerObserverImpl> handlerObserver = std::make_shared<ProtectionHandlerObserverImpl>();
// Create the consumption settings object from the publishing license.
mip::ProtectionHandler::ConsumptionSettings consumptionSettings = mip::ProtectionHandler::ConsumptionSettings(serializedPublishingLicense);
// Create/get the publishing handler from the publishing settings, observer, and promise.
mEngine->CreateProtectionHandlerForConsumptionAsync(consumptionSettings, handlerObserver, handlerPromise);
auto handler = handlerFuture.get();