Creating a new directory from C# with Encrypting File System switched on

前端 未结 3 998
刺人心
刺人心 2021-01-05 21:15

Has anyone created a new directory from C# with Encrypting File System switched on?

Additionally any information on doing this from an install would be helpful too.<

3条回答
  •  春和景丽
    2021-01-05 21:46

    Creating an encrypted directory would be a two step process - create it using Directory.CreateDirectory and then encrypt it using the Win32 function EncryptFile. Sample code -

    using System;
    using System.IO;
    using System.Runtime.InteropServices;
    
    namespace EncryptDir
    {
        public class Sample
        {
            DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            static extern bool EncryptFile(string filename);
    
            public static void Main ()
            {
                Directory.CreateDirectory("MyEncryptedDirectory");
                EncryptFile("MyEncryptedDirectory");
            }
    }
    

    References:
    EncryptFile Function @ MSDN
    Handling encrypted files and directories @ MSDN

提交回复
热议问题