FileInfo.Decrypt Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Descifra un archivo cifrado por la cuenta actual mediante el Encrypt() método .
public:
void Decrypt();
[System.Runtime.InteropServices.ComVisible(false)]
public void Decrypt();
public void Decrypt();
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.Decrypt : unit -> unit
member this.Decrypt : unit -> unit
Public Sub Decrypt ()
- Atributos
Excepciones
Se especificó una unidad no válida.
No se encontró el archivo descrito por el objeto actual FileInfo .
Error de E/S al abrir el archivo.
El sistema de archivos no es NTFS.
El sistema operativo actual no es Microsoft Windows NT ni posterior.
El archivo descrito por el objeto actual FileInfo es de solo lectura.
O bien
Esta operación no se admite en la plataforma actual.
O bien
El autor de la llamada no tiene el permiso necesario.
Ejemplos
En el ejemplo de código siguiente se usa el Encrypt método y el Decrypt método para cifrar y descifrar un archivo.
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
Comentarios
El Decrypt método permite descifrar un archivo cifrado mediante el Encrypt método . El Decrypt método solo puede descifrar los archivos cifrados mediante la cuenta de usuario actual.
Tanto el Encrypt método como el Decrypt método usan el proveedor de servicios criptográficos (CSP) instalado en el equipo y las claves de cifrado de archivos del proceso que llama al método .
El sistema de archivos actual debe tener el formato NTFS y el sistema operativo actual debe ser Microsoft Windows NT o posterior.