0

我有一个用于解密 MIP 消息的示例代码。

                MIP.Initialize(MipComponent.File);

                ApplicationInfo appInfo = new ApplicationInfo()
                {
                    ApplicationId = ConfigurationManager.AppSettings["ClientId"],
                    ApplicationName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name,
                    ApplicationVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
                };
                AuthDelegateImplementation authDelegate = new AuthDelegateImplementation();

                MipContext mipContext = MIP.CreateMipContext(appInfo,
                                         ConfigurationManager.AppSettings["FolderPathToStoreMIPData"],
                                         (Microsoft.InformationProtection.LogLevel)Enum.Parse(typeof(Microsoft.InformationProtection.LogLevel), ConfigurationManager.AppSettings["MIPLogLevel"], true),
                                         null,
                                         null);

                var profileSettings = new FileProfileSettings
                (
                    mipContext,
                    CacheStorageType.OnDiskEncrypted,
                    new ConsentDelegateImplementation()
                );

                var fileProfile = Task.Run(async () => await MIP.LoadFileProfileAsync(profileSettings)).Result;

                var customSettings = new List<KeyValuePair<string, string>>();
                customSettings.Add(new KeyValuePair<string, string>("enable_msg_file_type", "true"));

                var engineSettings = new FileEngineSettings(ConfigurationManager.AppSettings["EngineId"], authDelegate, "", CultureInfo.CurrentCulture.Name)
                {
                    Identity = new Identity(ConfigurationManager.AppSettings["FileEngineIdentityEmail"]),
                    CustomSettings = customSettings,
                    ProtectionOnlyEngine = true
                };

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

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

                var temp = Task.Run(async () => await handler.GetDecryptedTemporaryFileAsync()).Result;

此代码工作正常,能够使用 Microsoft.InformationProtection.File 库版本 1.9.90 解密消息,但对于所有后续库(1.10.93、1.10.97、1.10.98、1.11.53),它会立即停止行中的错误var temp = Task.Run(async () => await handler.GetDecryptedTemporaryFileAsync()).Result;

在 MPI 日志中,它在此时停止:

Info    2021-11-18 09:27:45.936 file_handler_impl.cpp:1203  MIPIntegration (30836)  "Starting API call: file_get_decrypted_file_path_async scenarioId=18b55f84-bcbe-4d8e-b83d-34824fe98bf6" mipns::FileHandlerImpl::GetDecryptedTemporaryFileAsync  36560
Trace   2021-11-18 09:27:45.936 default_task_dispatcher_delegate.cpp:84 MIPIntegration (30836)  "Executing task 'ApiObserver-2' on a new detached thread"   mipns::DefaultTaskDispatcherDelegate::ExecuteTaskOnIndependentThread    36560
Info    2021-11-18 09:27:45.936 file_handler_impl.cpp:1203  MIPIntegration (30836)  "Ended API call: file_get_decrypted_file_path_async"    mipns::FileHandlerImpl::GetDecryptedTemporaryFileAsync  36560
Info    2021-11-18 09:27:45.936 file_handler_impl.cpp:1203  MIPIntegration (30836)  "Starting API task: file_get_decrypted_file_path_async scenarioId=18b55f84-bcbe-4d8e-b83d-34824fe98bf6" mipns::FileHandlerImpl::GetDecryptedTemporaryFileAsync  29924
Info    2021-11-18 09:27:45.936 file_format_base.cpp:130    MIPIntegration (30836)  "Protection from input: [Encrypt-Only]" mipns::FileFormatBase::GetProtection    29924
Trace   2021-11-18 09:27:45.937 std_stream.cpp:88   MIPIntegration (30836)  "Creating output stream on: mip_data\temp\ede93557-cb44-42f2-851f-b80299f6ca28.msg" mipns::StdStream::CreateNew 29924
Info    2021-11-18 09:27:45.937 file_format_base.cpp:130    MIPIntegration (30836)  "Protection from input: [Encrypt-Only]" mipns::FileFormatBase::GetProtection    29924
Trace   2021-11-18 09:27:45.937 std_stream.cpp:75   MIPIntegration (30836)  "Creating input stream on: mip_data\temp\ede93557-cb44-42f2-851f-b80299f6ca28.msg"  mipns::StdStream::OpenInput 29924
Info    2021-11-18 09:27:45.937 file_format_base.cpp:226    MIPIntegration (30836)  "Start removing protection and updating properties" mipns::FileFormatBase::RemoveProtectionAndUpdateProperties  29924
Info    2021-11-18 09:27:45.937 msg_file_format.cpp:465 MIPIntegration (30836)  "Removing protection"   mipns::MsgFileFormat::RemoveProtectionAndUpdatePropertiesImpl   29924
Trace   2021-11-18 09:27:45.937 compound_file_storage_impl.cpp:183  MIPIntegration (30836)  "Open stream: Root\ DRMContent" mipns::CompoundFileStorageImpl::OpenStream  29924
Info    2021-11-18 09:27:45.938 file_format_base.cpp:130    MIPIntegration (30836)  "Protection from input: [Encrypt-Only]" mipns::FileFormatBase::GetProtection    29924
Trace   2021-11-18 09:27:45.938 protection_helper_impl.cpp:155  MIPIntegration (30836)  "Decrypting"    mipns::ProtectionHelperImpl::Decrypt    29924
Trace   2021-11-18 09:27:45.938 protection_handler_impl.cpp:258 MIPIntegration (30836)  " +ProtectionHandlerImpl::CreateProtectedStream"    mipns::ProtectionHandlerImpl::CreateProtectedStream 29924
Trace   2021-11-18 09:27:45.938 protection_handler_impl.cpp:277 MIPIntegration (30836)  " -ProtectionHandlerImpl::CreateProtectedStream"    mipns::ProtectionHandlerImpl::CreateProtectedStream 29924
Trace   2021-11-18 09:27:45.938 compound_file.cpp:167   MIPIntegration (30836)  "Open compound file for read"   mipns::CompoundFile::OpenRead   29924
Trace   2021-11-18 09:27:45.938 compound_file.cpp:176   MIPIntegration (30836)  "Open compound file for write"  mipns::CompoundFile::OpenWrite  29924
4

0 回答 0