次の方法で共有


Microsoft Information Protection SDK - 保護ハンドラーの概念

MIP Protection SDK では、 mip::ProtectionHandler は、保護されたストリームとバッファーの暗号化と復号化、アクセス チェックの実行、公開ライセンスの取得、保護された情報からの属性の取得を行うための関数を公開します。

要求事項

特定のファイルを操作する ProtectionHandler を作成するには、次のものが必要です。

  • mip::MipContext
  • mip::ProtectionProfile
  • ProtectionProfile に追加された mip::ProtectionEngine
  • mip::ProtectionHandler::Observerを継承するクラス。
  • mip::ProtectionDescriptor または公開ライセンス

保護ハンドラーを作成する

mip::ProtectionHandler オブジェクトは、 保護 操作または 消費 操作用に構築されます。 ハンドラーは、シナリオに応じて、4 つの関数のいずれかを使用して作成されます。

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

これらの関数は、 mip::ProtectionHandler::PublishingSettings または mip::ProtectionHandler::ConsumptionSettings オブジェクトを受け入れます。

発行ハンドラーを作成する

発行ハンドラーを作成するには、次の 3 つの手順が必要です。

  1. mip::ProtectionDescriptor オブジェクトを作成します。
  2. mip::ProtectionDescriptorを使用して、mip::ProtectionHandler::PublishingSettingsをインスタンス化します。
  3. mip::ProtectionEngine::CreateProtectionHandlerForPublishingAsync()を呼び出し、PublishingSettingsオブジェクト、オブザーバー、Promise を渡します。

記述子から作成する

まだ保護されていないコンテンツを保護する場合、またはコンテンツに新しい保護を適用する場合 (暗号化が解除されたことを意味する場合)、 mip::ProtectionDescriptor を構築する必要があります。 構築後、 mip::ProtectionHandler::PublishingSettings() オブジェクトをインスタンス化するために使用されます。 結果は、 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;

ProtectionHandler オブジェクトを正常に作成したら、保護操作 (暗号化/復号化) を実行できます。 発行ライセンスは、ハンドラーから取得して、暗号化されたコンテンツと共に保存する必要があります。 公開ライセンスは、handler->GetSerializedPublishingLicense(); を呼び出してフェッチできます。

対応する公開ライセンスのない保護されたコンテンツを 復号化することはできません

従量課金ハンドラーを作成する

発行ハンドラーを作成するには、次の 3 つの手順が必要です。

  1. 保護されたコンテンツから、シリアル化された発行ライセンスを std::vector<uint8_t> として抽出します。
  2. シリアル化された発行ライセンスを使用して、 mip::ProtectionHandler::ConsumptionSettingsをインスタンス化します。
  3. mip::ProtectionEngine::CreateProtectionHandlerForConsumptionAsync() を呼び出し、ConsumptionSettings オブジェクト、オブザーバー、Promise を渡します。

この例では、発行ライセンスが既にいくつかのソースから読み取られ、 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();