[英]Detect that file is protected by Microsoft Azure Information Protection
Currently, our app doesn't support files that are protected by Azure/Microsoft Information Protection ( https://learn.microsoft.com/en-us/azure/information-protection/what-is-information-protection ).目前,我们的应用程序不支持受 Azure/Microsoft 信息保护 ( https://learn.microsoft.com/en-us/azure/information-protection/what-is-information-protection ) 保护的文件。 I want to inform the user that our app doesn't support these files or give them a warning that functionalities are more limited.
我想通知用户我们的应用程序不支持这些文件,或者警告他们功能更加有限。
I have found one way to peek if the file is protected here: https://learn.microsoft.com/en-us/information-protection/develop/quick-app-initialization-csharp我找到了一种查看文件是否受保护的方法: https ://learn.microsoft.com/en-us/information-protection/develop/quick-app-initialization-csharp
Although this could work, it is too much overhead to configure this approach.尽管这可行,但配置此方法的开销太大。
Is there a fast, simple clean way to know that a file is protected by Azure/Microsoft Information Protection?是否有一种快速、简单、干净的方法来了解文件是否受 Azure/Microsoft 信息保护保护?
For Word, Excel and PowerPoint documents, I could try to open these files as ZIP files (because Office document files are ZIP files) and look for an 'EncryptedPackage' file in the root folder.对于 Word、Excel 和 PowerPoint 文档,我可以尝试将这些文件作为 ZIP 文件打开(因为 Office 文档文件是 ZIP 文件)并在根文件夹中查找“EncryptedPackage”文件。 But maybe there is a more conventional way.
但也许有更传统的方式。
For Word, Excel and PowerPoint documents we can zip and unzip files using System.IO.Compression
对于 Word、Excel 和 PowerPoint 文档,我们可以使用
System.IO.Compression
压缩和解压缩文件
Zip file:压缩文件:
Unzip Files:解压缩文件:
Snippet for Encryption and Decryption of text文本加解密片段
string Path = @"C:\Static\";
string zipPath = @"C:\Temp\Zip\result.zip";
//To Zip the files
ZipFile.CreateFromDirectory(Path, zipPath);
//to Unzip the files
ZipFile.ExtractToDirectory(zipPath, @"C:\UnZipped\");
Encryption Code:加密代码:
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);
For File protection need to use the below namespace对于文件保护需要使用以下命名空间
using Microsoft.Office.Interop.Excel- excel
using Microsoft.Office.Interop.Word - word
WorkbookObject.Password = password; WorkbookObject.Password = 密码; WorkbookObject.SaveAs("FileName.xls")
WorkbookObject.SaveAs("文件名.xls")
for more information on file protection use this link有关文件保护的更多信息,请使用此链接
I was also looking for the solution to this.我也在寻找解决方案。 I found following links helpful:
我发现以下链接很有帮助:
https://learn.microsoft.com/en-us/information-protection/develop/concept-mip-metadata 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 https://learn.microsoft.com/en-us/information-protection/develop/concept-mip-metadata#contentbits
We use apache tika as parser, through OOXMLParser we get the metadata of the file.我们使用 apache tika 作为解析器,通过 OOXMLParser 我们得到文件的元数据。
As per the documentation:根据文档:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.