skip to Main Content

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). 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

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?

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. But maybe there is a more conventional way.

2

Answers


  1. For Word, Excel and PowerPoint documents we can zip and unzip files using System.IO.Compression

    Zip file:

    enter image description here

    Unzip Files:

    enter image description here

    Snippet for Encryption and Decryption of text

    enter image description here

                string Path = @"C:Static";
                string zipPath = @"C:TempZipresult.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.SaveAs("FileName.xls")

    for more information on file protection use this link

    Login or Signup to reply.
  2. 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#contentbits

    We use apache tika as parser, through OOXMLParser we get the metadata of the file.

    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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search