我们如何使用 MIP SDK 加密 PDF 文件?

How can we encrypt a PDF file using MIP SDK?

基本上我们的需求是下载现有的pdf文档(有MIP加密),然后解密PDF文件,修改PDF中的内容,然后加密回来。我正在使用文件 SDK。直到修改我能够执行的内容,现在我想加密文件。设置标签时(已从 protection.office.com 启用加密),出现错误 “TemplateNotFoundException:无法识别的模板 ID。,”。 请提出建议。

var result = Task.Run(async () => await handler.CommitAsync(options.OutputName)).Result;

似乎与标签关联的 RMS 保护模板已被删除或设置为存档。您可以删除并 re-create 该标签,或者您必须使用 AIP 服务 cmdlet 来调查您的模板之一是否已设置为存档或删除。

您可以使用Get-AIPServiceTemplate列出模板。模板名称应与您的标签匹配。

如果模板设置为存档,使用Set-AIPSerivceTemplate将状态设置回已发布。如果模板不存在,您可以删除标签并重新开始(尽管删除模板很奇怪),或者您可以使用 PowerShell 更新保护设置。

This doc 描述了如何通过 PowerShell 管理标签。你会做这样的事情:

get-label | where {$_.displayname -eq "TOP SECRET"} | fl displayname,labelactions

这将输出:

DisplayName  : TOP SECRET
LabelActions : {{"Type":"encrypt","SubType":null,"Settings":[{"Key":"disabled","Value":"false"},{"Key":"protectiontype"
               ,"Value":"template"},{"Key":"templateid","Value":"0e7fea72-7bba-4438-a070-95c292cd6f8c"},{"Key":"templat
               earchived","Value":"True"},{"Key":"linkedtemplateid","Value":"0e7fea72-7bba-4438-a070-95c292cd6f8c"},{"K
               ey":"contentexpiredondateindaysornever","Value":"Never"},{"Key":"offlineaccessdays","Value":"-1"},{"Key"
               :"rightsdefinitions","Value":"[{\"Identity\":\"miltor.onmicrosoft.com\",\"Rights\":\"VIEW,VIEWRIGHTSDATA
               ,DOCEDIT,EDIT,PRINT,EXTRACT,REPLY,REPLYALL,FORWARD,OBJMODEL\"},{\"Identity\":\"microsoft.com\",\"Rights\
               ":\"VIEW,VIEWRIGHTSDATA,OBJMODEL\"},{\"Identity\":\"test@milt0r.com\",\"Rights\":\"PROJECT\"}]"}]}, {"Ty
               pe":"applycontentmarking","SubType":"header","Settings":[{"Key":"fontsize","Value":"10"},{"Key":"placeme
               nt","Value":"Header"},{"Key":"text","Value":"Property of Contoso"},{"Key":"fontcolor","Value":"#000000"}
               ,{"Key":"margin","Value":"5"},{"Key":"alignment","Value":"Left"},{"Key":"disabled","Value":"false"}]}, {
               "Type":"applycontentmarking","SubType":"footer","Settings":[{"Key":"fontsize","Value":"10"},{"Key":"plac
               ement","Value":"Footer"},{"Key":"text","Value":"Property of Contoso"},{"Key":"fontcolor","Value":"#00000
               0"},{"Key":"margin","Value":"5"},{"Key":"alignment","Value":"Left"},{"Key":"disabled","Value":"false"}]}
               , {"Type":"applywatermarking","SubType":null,"Settings":[{"Key":"fontsize","Value":"10"},{"Key":"layout"
               ,"Value":"Diagonal"},{"Key":"fontcolor","Value":"#000000"},{"Key":"disabled","Value":"false"},{"Key":"te
               xt","Value":"Property of Contoso"}]}}

在那个 JSON 中找到 linkedtemplateid: {"Key":"linkedtemplateid","Value":"0e7fea72-7bba-4438-a070-95c292cd6f8c"}

这是RMS 中应该存在的模板ID,用于为标签提供保护操作。如果不存在,请使用 Add-AIPServiceTemplate to create a new template and update the label by Set-Label 并提供 EncryptionProtectionTypeEncryptionRightsDefinitions.