共用方式為


Microsoft 資訊保護 SDK - 保護 SDK 引擎概念

實作:新增保護引擎

在檔案 SDK 中,類別 mip::ProtectionProfile 是所有 SDK 作業的根類別。 建立設定檔之後,我們現在可以將引擎新增至設定檔。

下列範例示範如何針對單一已驗證的使用者使用單一引擎。

實作:建立保護引擎設定

與設定檔類似,引擎也需要設定物件 。 mip::ProtectionEngine::Settings 此物件會儲存唯一的引擎識別碼、可用於偵錯或遙測的可自訂用戶端資料,以及選擇性地儲存地區設定。

在這裡,我們會建立 ProtectionEngine::Settings 名為 engine設定 的物件。

ProtectionEngine::Settings engineSettings("UniqueID", "");

注意

如果使用此方法建立保護設定物件,您也必須透過 手動設定 ProtectionEngine 上的身分識別設定 setIdentity() 或透過 setCloud() 的目標雲端環境。

最佳做法是,第一個參數 id 應該是一些可讓引擎輕鬆連線至相關聯使用者或 mip::Identity 物件的專案。 若要使用 mip::Identity 初始化設定:

ProtectionEngine::Settings engineSettings(mip::Identity("Bob@Contoso.com", "");

以這種方式建立引擎設定請務必透過下列方式明確設定唯一的 engineId:

engineSettings.SetEngineId(engineId);

使用使用者名稱或電子郵件 有助於確保每次使用者使用服務或應用程式時,都會載入相同的引擎。

實作:新增保護引擎

若要新增引擎,我們將回到用來載入設定檔的未來/承諾模式。 我們不會為 mip::ProtectionProfile 建立承諾,而是使用 mip::ProtectionEngine


  //auto profile will be std::shared_ptr<mip::ProtectionProfile>
  auto profile = profileFuture.get();

  //Create the ProtectionEngine::Settings object
  ProtectionEngine::Settings engineSettings("UniqueID", "");

  //Create a promise for std::shared_ptr<mip::ProtectionEngine>
  auto enginePromise = std::make_shared<std::promise<std::shared_ptr<mip::ProtectionEngine>>>();

  //Instantiate the future from the promise
  auto engineFuture = enginePromise->get_future();

  //Add the engine using AddEngineAsync, passing in the engine settings and the promise
  profile->AddEngineAsync(engineSettings, enginePromise);

  //get the future value and store in std::shared_ptr<mip::ProtectionEngine>
  auto engine = engineFuture.get();

上述程式碼的最終結果是,我們已成功將已驗證使用者的引擎新增至設定檔。

實作:列出範本

使用新增的引擎,現在可以藉由呼叫 engine->GetTemplatesAsync() 來列出已驗證使用者可用的所有敏感度範本。

GetTemplatesAsync() 將會擷取範本識別碼的清單。 結果會儲存在 的 std::shared_ptr<std::string> 向量中。

實作:ListSensitivityTemplates()

auto loadPromise = std::make_shared<std::promise<shared_ptr<vector<string>>>>();
std::future<std::shared_ptr<std::vector<std::string>>> loadFuture = loadPromise->get_future();
mEngine->GetTemplatesAsync(engineObserver, loadPromise);
auto templates = loadFuture.get();

實作:列印範本識別碼

//Iterate through all template IDs in the vector
for (const auto& temp : *templates) {
  cout << "Template:" << "\n\tId: " << temp << endl;
}

列印名稱是顯示我們已成功從服務提取原則並能夠取得範本的簡單方式。 若要套用範本,則需要範本識別碼。

只有藉由檢查 的結果 ComputeActions() ,才能透過原則 SDK 將範本對應至標籤。

後續步驟

現在已載入設定檔,引擎已新增,而且我們有範本,我們可以新增處理常式,開始從檔案讀取、寫入或移除範本。 請參閱 保護處理常式概念