Exemple #1
0
        public static void Decrypt(string path)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                SysFile.Decrypt(path);
                return;
            }

            String fullPath       = Path.GetFullPath(path);
            string normalizedPath = Path.NormalizeLongPath(fullPath);

            if (NativeMethods.DecryptFile(normalizedPath, 0))
            {
                return;
            }
            int errorCode = Marshal.GetLastWin32Error();

            if (errorCode == NativeMethods.ERROR_ACCESS_DENIED)
            {
                var di = new DriveInfo(Path.GetPathRoot(normalizedPath));
                if (!String.Equals("NTFS", di.DriveFormat))
                {
                    throw new NotSupportedException("NTFS drive required for file encryption");
                }
            }
            Common.ThrowIOError(errorCode, fullPath);
        }