微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用MIP SDK解密.msg文件时发生异常:NoPolicyException:标签策略不包含数据

如何解决使用MIP SDK解密.msg文件时发生异常:NoPolicyException:标签策略不包含数据

我跟随thisthis使用MIP SDK解密.msg。以下是我的代码

class Program
{
    private const string clientId = "[test client id here]";
    private const string appName = "MIPSDKTestApp";

    static void Main(string[] args)
    {
        Console.WriteLine("Provide path to protected msg file:");
        string inputFilePath = Console.ReadLine();
        string outputFilePath = Path.Combine(Path.GetDirectoryName(inputFilePath),"Unprotected_" + Path.GetFileName(inputFilePath));

        // Initialize Wrapper for File API operations.
        MIP.Initialize(MipComponent.File);

        // Create ApplicationInfo,setting the clientID from Azure AD App Registration as the ApplicationId.
        ApplicationInfo appInfo = new ApplicationInfo()
        {
            ApplicationId = clientId,ApplicationName = appName,ApplicationVersion = "1.0.0"
        };

        // Instantiate the AuthDelegateImpl object,passing in AppInfo.
        AuthDelegateImplementation authDelegate = new AuthDelegateImplementation(appInfo);

        MipContext mipContext = MIP.CreateMipContext(appInfo,"mip_data",LogLevel.Trace,null,null);

        // Initialize and instantiate the File Profile.
        // Create the FileProfileSettings object.
        // Initialize file profile settings to create/use local state.
        var profileSettings = new FileProfileSettings(mipContext,CacheStorageType.OndiskEncrypted,new ConsentDelegateImplementation());

        // Load the Profile async and wait for the result.
        var fileProfile = Task.Run(async () => await MIP.LoadFileProfileAsync(profileSettings)).Result;

        // Create a FileEnginesettings object,then use that to add an engine to the profile.
        var customSettings = new List<keyvaluePair<string,string>>();
        customSettings.Add(new keyvaluePair<string,string>("enable_msg_file_type","true"));

        // Create a FileEnginesettings object,then use that to add an engine to the profile.
        var enginesettings = new FileEnginesettings("[user@tenant]",authDelegate,"",CultureInfo.CurrentCulture.Name);
        enginesettings.Identity = new Identity("[user@tenant]");

        //set custom settings for the engine
        enginesettings.CustomSettings = customSettings;

        var fileEngine = Task.Run(async () => await fileProfile.AddEngineAsync(enginesettings)).Result; // EXCEPTION THROWN HERE

        var handler = Task.Run(async () => await fileEngine.CreateFileHandlerAsync(inputFilePath,inputFilePath,true)).Result;

        handler.RemoveProtection();

        var result = Task.Run(async () => await handler.CommitAsync(outputFilePath)).Result;
        
        // Application Shutdown
        handler = null; // This will be used in later quick starts.
        fileEngine = null;
        fileProfile = null;
        mipContext = null;

    }
}

但是它会引发以下错误

nopolicyException:标签策略不包含数据,CorrelationId = 3268dfdf-2ea3-4958-9c72-fe88ae3c6f59,CorrelationId.Description = PolicyProfile,nopolicyError.Category = SyncFile,nopolicyError.Category = SyncFile

at

var fileEngine = Task.Run(async () => await fileProfile.AddEngineAsync(enginesettings)).Result;

Canyone可以指出我在做什么错吗?

解决方法

您似乎尚未在安全和合规中心(https://security.microsoft.com)中配置或发布标签策略。

对于此用例,您不一定需要发布标签。将此添加到您的引擎设置:

engineSettings.ProtectionOnlyEngine = true;

这将跳过加载策略,并应允许您解密MSG文件。不过,在发布标签政策并删除该设置之前,您将无法阅读或应用标签。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。