Compartilhar via


SDK de Proteção de Informações Microsoft - Conceitos sobre o manipulador de proteção

No SDK de Proteção MIP, o mip::ProtectionHandler expõe as funções para criptografar e descriptografar fluxos e buffers protegidos, executar verificações de acesso, obter a licença de publicação e obter atributos das informações protegidas.

Requisitos

Criar um ProtectionHandler para trabalhar com um arquivo específico requer:

  • Um mip::MipContext
  • Um mip::ProtectionProfile
  • Um mip::ProtectionEngine adicionado ao ProtectionProfile
  • Uma classe que herda mip::ProtectionHandler::Observer.
  • Uma mip::ProtectionDescriptor ou licença de publicação

Criar um manipulador de proteção

mip::ProtectionHandler os objetos são construídos para operações de proteção ou consumo . O manipulador é criado usando uma das quatro funções, dependendo do cenário.

  • mip::ProtectionEngine->CreateProtectionHandlerForConsumptionAsync()
  • mip::ProtectionEngine->CreateProtectionHandlerForConsumption()
  • mip::ProtectionEngine->CreateProtectionHandlerForPublishingAsync()
  • mip::ProtectionEngine->CreateProtectionHandlerForPublishing()

Essas funções aceitam um mip::ProtectionHandler::PublishingSettings ou mip::ProtectionHandler::ConsumptionSettings objeto.

Criar um manipulador de publicação

A criação de um manipulador de publicação requer três etapas:

  1. Crie um objeto mip::ProtectionDescriptor.
  2. Use o mip::ProtectionDescriptor para criar uma instância para mip::ProtectionHandler::PublishingSettings.
  3. Chame mip::ProtectionEngine::CreateProtectionHandlerForPublishingAsync() passando no objeto PublishingSettings, no observador e na promessa.

Criar no descritor

Se estiver protegendo conteúdo que ainda não foi protegido ou estiver aplicando nova proteção a conteúdo, o que implica que ele deve ter sido descriptografado, será necessário construir um mip::ProtectionDescriptor. Uma vez construído, ele é usado para instanciar o mip::ProtectionHandler::PublishingSettings() objeto. O resultado é retornado por meio do 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;

Depois de criar com êxito o objeto ProtectionHandler, as operações de proteção (criptografar/descriptografar) podem ser realizadas. A licença de publicação deve ser buscada do manipulador e armazenada com o conteúdo criptografado. A licença de publicação pode ser buscada chamando: handler->GetSerializedPublishingLicense();

O conteúdo protegido sem a licença de publicação correspondente não pode ser descriptografado.

Criar o manipulador de consumo

A criação de um manipulador de publicação requer três etapas:

  1. Extraia do conteúdo protegido uma licença de publicação serializada como std::vector<uint8_t>.
  2. Use a licença de publicação serializada para instanciar mip::ProtectionHandler::ConsumptionSettings.
  3. Chame mip::ProtectionEngine::CreateProtectionHandlerForConsumptionAsync() passando no objeto ConsumptionSettings, no observador e na promessa.

Este exemplo pressupõe que a licença de publicação já foi lida de alguma origem e armazenada em 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();