【问题标题】:Detect that file is protected by Microsoft Azure Information Protection检测到该文件受 Microsoft Azure 信息保护保护
【发布时间】:2022-12-20 17:14:29
【问题描述】:

目前,我们的应用程序不支持受 Azure/Microsoft 信息保护 (https://learn.microsoft.com/en-us/azure/information-protection/what-is-information-protection) 保护的文件。我想通知用户我们的应用程序不支持这些文件,或者警告他们功能更加有限。

我找到了一种查看文件是否受保护的方法:https://learn.microsoft.com/en-us/information-protection/develop/quick-app-initialization-csharp

尽管这可行,但配置此方法的开销太大。

是否有一种快速、简单、干净的方法来了解文件是否受 Azure/Microsoft 信息保护保护?

对于 Word、Excel 和 PowerPoint 文档,我可以尝试将这些文件作为 ZIP 文件打开(因为 Office 文档文件是 ZIP 文件)并在根文件夹中查找“EncryptedPackage”文件。但也许有更传统的方式。

【问题讨论】:

  • 你能做到吗?我需要为 java 做同样的事情。

标签: .net excel azure ms-word protection


【解决方案1】:

对于 Word、Excel 和 PowerPoint 文档,我们可以使用System.IO.Compression 压缩和解压缩文件

压缩文件:

解压缩文件:

文本加解密片段

            string Path = @"C:Static";
            string zipPath = @"C:TempZip
esult.zip";

            //To Zip the files
            ZipFile.CreateFromDirectory(Path, zipPath);

            //to Unzip the files
            ZipFile.ExtractToDirectory(zipPath, @"C:UnZipped");

加密代码:

           byte[] key_Array;
            byte[] Encrypt_Array = UTF8Encoding.UTF8.GetBytes(txtPlain.Text);

            string key = "Some Securty Key";
            if (true)
            {
                MD5CryptoServiceProvider hashingMd5 = new MD5CryptoServiceProvider();
                keyArray = hashingMd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                hashingMd5.Clear();
            }
            TripleDESCryptoServiceProvider tdesSp = new TripleDESCryptoServiceProvider();
            tdesSp.Key = key_Array;
            tdesSp.Mode = CipherMode.ECB;
            tdesSp.Padding = PaddingMode.PKCS7;

            ICryptoTransform cTransform = tdesSp.CreateEncryptor();
            byte[] result_Array = cTransform.TransformFinalBlock(Encrypt_Array, 0, Encrypt_Array.Length);
            

对于文件保护需要使用下面的命名空间

using Microsoft.Office.Interop.Excel- excel
using Microsoft.Office.Interop.Word - word

WorkbookObject.Password = 密码; WorkbookObject.SaveAs("文件名.xls")

有关文件保护的更多信息,请使用link

【讨论】:

  • 感谢您的回答。不幸的是,这不会很好地工作。检查文件的代码是未安装 Office 的服务器应用程序。我可以打开 Office 文档(当它们采用较新的格式时,例如 xlsx)作为 ZIP 容器并查找“EncryptedPackage”文件。但我希望有一种更传统的方式。
  • 不需要安装任何 Office 的唯一方法是使用 Open XML SDK (learn.microsoft.com/en-us/office/open-xml/open-xml-sdk)。
【解决方案2】:

我也在寻找解决方案。 我发现以下链接很有帮助:

https://learn.microsoft.com/en-us/information-protection/develop/concept-mip-metadata

https://learn.microsoft.com/en-us/information-protection/develop/concept-mip-metadata#contentbits

我们使用 apache tika 作为解析器,通过 OOXMLParser 我们得到文件的元数据。

根据文档:

When a file is labeled with MIP SDK, the only outcomes for contentBits will be 0x0 if the file is unprotected or 0x8 if the file is protected

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 2017-09-18
    • 2015-09-05
    • 2022-08-29
    • 2012-05-28
    相关资源
    最近更新 更多