Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
In MIP Protection SDK mip::ProtectionHandler espone le funzioni per crittografare e decrittografare flussi e buffer protetti, eseguire controlli di accesso, ottenere la licenza di pubblicazione e ottenere attributi dalle informazioni protette.
Requisiti
La creazione di un ProtectionHandler per lavorare con un file specifico richiede:
- Un
mip::MipContext - Un
mip::ProtectionProfile - Oggetto
mip::ProtectionEngineaggiunto all'oggettoProtectionProfile - Classe che eredita
mip::ProtectionHandler::Observer. - Una licenza
mip::ProtectionDescriptoro di pubblicazione
Creare un gestore di protezione
mip::ProtectionHandler gli oggetti vengono costruiti per operazioni di protezione o consumo . Il gestore viene creato usando una delle quattro funzioni, a seconda dello scenario.
mip::ProtectionEngine->CreateProtectionHandlerForConsumptionAsync()mip::ProtectionEngine->CreateProtectionHandlerForConsumption()mip::ProtectionEngine->CreateProtectionHandlerForPublishingAsync()mip::ProtectionEngine->CreateProtectionHandlerForPublishing()
Queste funzioni accettano un mip::ProtectionHandler::PublishingSettings oggetto o mip::ProtectionHandler::ConsumptionSettings .
Creare un gestore di pubblicazione
La creazione di un gestore di pubblicazione richiede tre passaggi:
- Creare un oggetto
mip::ProtectionDescriptor. - Utilizzare
mip::ProtectionDescriptorper istanziaremip::ProtectionHandler::PublishingSettings. - Chiamare
mip::ProtectionEngine::CreateProtectionHandlerForPublishingAsync(), passando l'oggettoPublishingSettings, l'osservatore e la promessa.
Crea da descrittore
Se si protegge il contenuto che non è ancora stato protetto o quando si applica una nuova protezione al contenuto, il che implica che è stato decrittografato, deve essere costruito un oggetto mip::ProtectionDescriptor . Una volta costruito, viene utilizzato per istanziare l'oggetto mip::ProtectionHandler::PublishingSettings(). Il risultato viene restituito tramite 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;
Dopo aver creato correttamente l'oggetto ProtectionHandler , è possibile eseguire operazioni di protezione (crittografia/decrittografia). La licenza di pubblicazione deve essere recuperata dal gestore e archiviata con il contenuto crittografato. La licenza di pubblicazione può essere recuperata chiamando: handler->GetSerializedPublishingLicense();
Non è possibile decrittografare il contenuto protetto senza la licenza di pubblicazione corrispondente.
Creare il gestore di consumo
La creazione di un gestore di pubblicazione richiede tre passaggi:
- Estrarre una licenza di pubblicazione serializzata come
std::vector<uint8_t>dal contenuto protetto. - Usare la licenza di pubblicazione serializzata per creare un'istanza di
mip::ProtectionHandler::ConsumptionSettings. - Chiama
mip::ProtectionEngine::CreateProtectionHandlerForConsumptionAsync()passando l'oggettoConsumptionSettings, l'osservatore e la promessa.
In questo esempio si presuppone che la licenza di pubblicazione sia già stata letta da un'origine e archiviata in 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();