File.Decrypt(String) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
메서드를 사용하여 현재 계정으로 암호화된 파일의 암호를 해독합니다 Encrypt(String) .
public:
static void Decrypt(System::String ^ path);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void Decrypt(string path);
public static void Decrypt(string path);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member Decrypt : string -> unit
static member Decrypt : string -> unit
Public Shared Sub Decrypt (path As String)
매개 변수
- path
- String
암호를 해독할 파일을 설명하는 경로입니다.
- 특성
예외
.NET Framework 및 .NET Core 버전 2.1 이전: path 매개 변수는 길이가 0인 문자열이거나 공백만 포함하거나 하나 이상의 잘못된 문자를 포함합니다. 메서드를 사용하여 잘못된 문자를 쿼리할 GetInvalidPathChars() 수 있습니다.
매개 변수는 path .입니다 null.
잘못된 드라이브를 지정했습니다.
매개 변수에 path 설명된 파일을 찾을 수 없습니다.
지정된 경로, 파일 이름 또는 둘 다 시스템 정의 최대 길이를 초과합니다.
현재 운영 체제는 Windows NT 이상이 아닙니다.
파일 시스템이 NTFS가 아닙니다.
매개 변수가 path 읽기 전용인 파일을 지정했습니다.
-또는-
이 작업은 현재 플랫폼에서 지원되지 않습니다.
-또는-
매개 변수가 path 디렉터리를 지정했습니다.
-또는-
호출자에게 필요한 권한이 없습니다.
예제
다음 코드 예제에서는 메서드와 Encrypt 메서드를 사용하여 Decrypt 파일을 암호화한 다음 암호를 해독합니다. 예제가 작동하려면 파일이 있어야 합니다.
using System;
using System.IO;
using System.Security.AccessControl;
namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
try
{
string FileName = "test.xml";
Console.WriteLine("Encrypt " + FileName);
// Encrypt the file.
AddEncryption(FileName);
Console.WriteLine("Decrypt " + FileName);
// Decrypt the file.
RemoveEncryption(FileName);
Console.WriteLine("Done");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadLine();
}
// Encrypt a file.
public static void AddEncryption(string FileName)
{
File.Encrypt(FileName);
}
// Decrypt a file.
public static void RemoveEncryption(string FileName)
{
File.Decrypt(FileName);
}
}
}
open System.IO
// Encrypt a file.
let addEncryption fileName = File.Encrypt fileName
// Decrypt a file.
let removeEncryption fileName = File.Decrypt fileName
let fileName = "test.xml"
printfn $"Encrypt {fileName}"
// Encrypt the file.
addEncryption fileName
printfn $"Decrypt {fileName}"
// Decrypt the file.
removeEncryption fileName
printfn "Done"
Imports System.IO
Imports System.Security.AccessControl
Module FileExample
Sub Main()
Try
Dim FileName As String = "test.xml"
Console.WriteLine("Encrypt " + FileName)
' Encrypt the file.
AddEncryption(FileName)
Console.WriteLine("Decrypt " + FileName)
' Decrypt the file.
RemoveEncryption(FileName)
Console.WriteLine("Done")
Catch e As Exception
Console.WriteLine(e)
End Try
Console.ReadLine()
End Sub
' Encrypt a file.
Sub AddEncryption(ByVal FileName As String)
File.Encrypt(FileName)
End Sub
' Decrypt the file.
Sub RemoveEncryption(ByVal FileName As String)
File.Decrypt(FileName)
End Sub
End Module
설명
이 Decrypt 메서드를 사용하면 메서드를 사용하여 암호화된 파일의 암호를 해독할 Encrypt 수 있습니다. 이 메서드는 Decrypt 현재 사용자 계정을 사용하여 암호화된 파일만 암호 해독할 수 있습니다.
Important
이 API는 NTFS EFS(파일 시스템 암호화)를 사용할 수 있는 Windows 플랫폼에서만 지원됩니다. 비 Windows 시스템, Windows Home Edition 시스템 또는 비 NTFS 드라이브에서 이를 사용하려고 하면 상황에 따라 PlatformNotSupportedException 또는 NotSupportedException 발생합니다.
.NET Core에서 이 API를 사용하는 것은 권장되지 않습니다. .NET Core로 이동하지만 여전히 명시적으로 Windows 대상으로 하는 애플리케이션에 이식성을 사용하도록 설정하는 데 포함됩니다.
이 메서드는 Decrypt 암호 해독 중인 파일에 대한 단독 액세스 권한이 필요하며 다른 프로세스가 파일을 사용하는 경우 예외가 발생합니다.
Encrypt 메서드와 Decrypt 메서드는 모두 컴퓨터에 설치된 CSP(암호화 서비스 공급자)와 메서드를 호출하는 프로세스의 파일 암호화 키를 사용합니다.
현재 파일 시스템의 형식은 NTFS여야 하며 현재 운영 체제는 NT 이상을 Windows 합니다.