示例#1
0
文件: File.cs 项目: etad4e5/coreclr
        public static void Decrypt(String path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            Contract.EndContractBlock();

            String fullPath = Path.GetFullPath(path);

            FileIOPermission.QuickDemand(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, fullPath, false, false);

            bool r = Win32Native.DecryptFile(fullPath, 0);

            if (!r)
            {
                int errorCode = Marshal.GetLastWin32Error();
                if (errorCode == Win32Native.ERROR_ACCESS_DENIED)
                {
                    // Check to see if the file system is not NTFS.  If so,
                    // throw a different exception.
                    DriveInfo di = new DriveInfo(Path.GetPathRoot(fullPath));
                    if (!String.Equals("NTFS", di.DriveFormat))
                    {
                        throw new NotSupportedException(Environment.GetResourceString("NotSupported_EncryptionNeedsNTFS"));
                    }
                }
                __Error.WinIOError(errorCode, fullPath);
            }
        }