FileInfo.Decrypt メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
Encrypt() メソッドを使用して現在のアカウントによって暗号化されたファイルを復号化します。
public:
void Decrypt();
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public void Decrypt ();
public void Decrypt ();
[System.Runtime.InteropServices.ComVisible(false)]
public void Decrypt ();
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
member this.Decrypt : unit -> unit
member this.Decrypt : unit -> unit
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.Decrypt : unit -> unit
Public Sub Decrypt ()
- 属性
正しくないドライブが指定されました。
現在の FileInfo オブジェクトで記述されているファイルが見つかりませんでした。
ファイルを開くときに、I/O エラーが発生しました。
このファイル システムは NTFS ではありません。
現在のオペレーティング システムは Microsoft Windows NT 以降ではありません。
現在の FileInfo オブジェクトで記述されているファイルは読み取り専用です。
- または -
この操作は、現在のプラットフォームではサポートされていません。
または
呼び出し元に、必要なアクセス許可がありません。
次のコード例では、 メソッドと メソッドをEncryptDecrypt使用して、ファイルの暗号化と暗号化解除を行います。
using namespace System;
using namespace System::IO;
using namespace System::Security::AccessControl;
static void Addencryption(String^ fileName)
{
// Create a new FileInfo object.
FileInfo^ fInfo = gcnew FileInfo(fileName);
if (!fInfo->Exists)
{
fInfo->Create();
}
// Add encryption.
fInfo->Encrypt();
}
static void Removeencryption(String^ fileName)
{
// Create a new FileInfo object.
FileInfo^ fInfo = gcnew FileInfo(fileName);
if (!fInfo->Exists)
{
fInfo->Create();
}
// Remove encryption.
fInfo->Decrypt();
}
int main()
{
try
{
String^ fileName = "c:\\MyTest.txt";
Console::WriteLine("Encrypt " + fileName);
// Encrypt the file.
Addencryption(fileName);
Console::WriteLine("Decrypt " + fileName);
// Decrypt the file.
Removeencryption(fileName);
Console::WriteLine("Done");
}
catch (IOException^ ex)
{
Console::WriteLine(ex->Message);
}
}
//This code produces output similar to the following;
//results may vary based on the computer/file structure/etc.:
//
//Encrypt c:\MyTest.txt
//Decrypt c:\MyTest.txt
//Done
using System;
using System.IO;
using System.Security.AccessControl;
namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
try
{
string FileName = @"c:\MyTest.txt";
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);
}
}
public static void AddEncryption(string FileName)
{
// Create a new FileInfo object.
FileInfo fInfo = new FileInfo(FileName);
if (!fInfo.Exists)
{
//Create the file.
fInfo.Create();
}
// Add encryption.
fInfo.Encrypt();
}
public static void RemoveEncryption(string FileName)
{
// Create a new FileInfo object.
FileInfo fInfo = new FileInfo(FileName);
if (!fInfo.Exists)
{
//Create the file.
fInfo.Create();
}
// Remove encryption.
fInfo.Decrypt();
}
}
}
//This code produces output similar to the following;
//results may vary based on the computer/file structure/etc.:
//
//Encrypt c:\MyTest.txt
//Decrypt c:\MyTest.txt
//Done
Imports System.IO
Imports System.Security.AccessControl
Module FileExample
Sub Main()
Try
Dim FileName As String = "c:\MyTest.txt"
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
End Sub
Sub AddEncryption(ByVal FileName As String)
' Create a new FileInfo object.
Dim fInfo As New FileInfo(FileName)
If fInfo.Exists = False Then
fInfo.Create()
End If
' Add encryption.
fInfo.Encrypt()
End Sub
Sub RemoveEncryption(ByVal FileName As String)
' Create a new FileInfo object.
Dim fInfo As New FileInfo(FileName)
If fInfo.Exists = False Then
fInfo.Create()
End If
' Remove encryption.
fInfo.Decrypt()
End Sub
End Module
'This code produces output similar to the following;
'results may vary based on the computer/file structure/etc.:
'
'Encrypt c:\MyTest.txt
'Decrypt c:\MyTest.txt
'Done
Decryptメソッドを使用すると、 メソッドを使用して暗号化されたファイルをEncrypt復号化できます。 メソッドは、現在の Decrypt ユーザー アカウントを使用して暗号化されたファイルのみを復号化できます。
メソッドと メソッドのEncryptDecrypt両方で、コンピューターにインストールされている暗号化サービス プロバイダー (CSP) と、 メソッドを呼び出すプロセスのファイル暗号化キーを使用します。
現在のファイル システムは NTFS 形式で、現在のオペレーティング システムは Microsoft Windows NT 以降である必要があります。
製品 | バージョン |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。