Poznámka:
Přístup k této stránce vyžaduje autorizaci. Můžete se zkusit přihlásit nebo změnit adresáře.
Přístup k této stránce vyžaduje autorizaci. Můžete zkusit změnit adresáře.
V sadě MIP Protection SDK mip::ProtectionHandler zpřístupňuje funkce pro šifrování a dešifrování chráněných datových proudů a vyrovnávacích pamětí, provádění kontrol přístupu, získání licence pro publikování a získávání atributů z chráněných informací.
Požadavky
Vytvoření pro ProtectionHandler práci s konkrétním souborem vyžaduje:
- Provede
mip::MipContext. - Provede
mip::ProtectionProfile. - A
mip::ProtectionEngineadded to theProtectionProfile - Třída, která dědí
mip::ProtectionHandler::Observer. - Licence
mip::ProtectionDescriptornebo publikování
Vytvoření obslužné rutiny ochrany
mip::ProtectionHandler objekty se vytvářejí pro operace ochrany nebo spotřeby . Obslužná rutina se vytvoří pomocí jedné ze čtyř funkcí v závislosti na scénáři.
mip::ProtectionEngine->CreateProtectionHandlerForConsumptionAsync()mip::ProtectionEngine->CreateProtectionHandlerForConsumption()mip::ProtectionEngine->CreateProtectionHandlerForPublishingAsync()mip::ProtectionEngine->CreateProtectionHandlerForPublishing()
Tyto funkce přijímají objekt mip::ProtectionHandler::PublishingSettings nebo objekt mip::ProtectionHandler::ConsumptionSettings .
Vytvoření obslužné rutiny publikování
Vytvoření obslužné rutiny publikování vyžaduje tři kroky:
- Vytvoření objektu
mip::ProtectionDescriptor - Použijte k
mip::ProtectionDescriptorvytvoření instancemip::ProtectionHandler::PublishingSettings. - Volání
mip::ProtectionEngine::CreateProtectionHandlerForPublishingAsync()předávající objektPublishingSettings, pozorovatele a příslibu
Vytvoření z popisovače
Pokud ochrana obsahu, který ještě není chráněný, nebo při použití nové ochrany obsahu, což znamená, že je dešifrovaný, mip::ProtectionDescriptor je nutné vytvořit. Po vytvoření se použije k vytvoření instance objektu mip::ProtectionHandler::PublishingSettings() . Výsledek se vrátí přes 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;
Po úspěšném vytvoření objektu ProtectionHandler je možné provádět operace ochrany (šifrování/dešifrování). Licence pro publikování musí být načtena z obslužné rutiny a uložena se šifrovaným obsahem. Licence pro publikování se dá načíst voláním: handler->GetSerializedPublishingLicense();
Chráněný obsah bez odpovídající licence publikování nelze dešifrovat.
Vytvoření obslužné rutiny consumption
Vytvoření obslužné rutiny publikování vyžaduje tři kroky:
- Extrahujte serializovanou licenci publikování jako
std::vector<uint8_t>z chráněného obsahu. - K vytvoření
mip::ProtectionHandler::ConsumptionSettingsinstance použijte serializovanou licenci pro publikování . - Volání
mip::ProtectionEngine::CreateProtectionHandlerForConsumptionAsync()předávající objektConsumptionSettings, pozorovatele a příslibu
Tento příklad předpokládá, že licence publikování již byla načtena z nějakého zdroje a uložena v 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();