ProtectedMemory.Unprotect(Byte[], MemoryProtectionScope) Método

Definición

Desprotege los datos de la memoria que se protegieron utilizando el método Protect(Byte[], MemoryProtectionScope).

public:
 static void Unprotect(cli::array <System::Byte> ^ encryptedData, System::Security::Cryptography::MemoryProtectionScope scope);
public static void Unprotect (byte[] encryptedData, System.Security.Cryptography.MemoryProtectionScope scope);
static member Unprotect : byte[] * System.Security.Cryptography.MemoryProtectionScope -> unit
Public Shared Sub Unprotect (encryptedData As Byte(), scope As MemoryProtectionScope)

Parámetros

encryptedData
Byte[]

La matriz de bytes de la memoria que se va a desproteger.

scope
MemoryProtectionScope

Uno de los valores de enumeración que especifica el ámbito de la protección de memoria.

Excepciones

El sistema operativo no admite este método. Este método sólo se puede utilizar con Windows 2000 o sistemas operativos posteriores.

encryptedData es null.

encryptedData está vacía.

o bien

No se implementó esta llamada.

o bien

NTSTATUS contiene un error.

Ejemplos

En el ejemplo siguiente se muestra cómo usar la protección de datos.

#using <System.Security.dll>

using namespace System;
using namespace System::Security::Cryptography;

int main()
{
   
   // Create the original data to be encrypted (The data length should be a multiple of 16).
   array<Byte>^secret = {1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4};
   
   // Encrypt the data in memory. The result is stored in the same array as the original data.
   ProtectedMemory::Protect( secret, MemoryProtectionScope::SameLogon );
   
   // Decrypt the data in memory and store in the original array.
   ProtectedMemory::Unprotect( secret, MemoryProtectionScope::SameLogon );
}
using System;
using System.Security.Cryptography;

public class MemoryProtectionSample
{

    public static void Main()
    {
        // Create the original data to be encrypted (The data length should be a multiple of 16).
        byte [] secret = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 };

        // Encrypt the data in memory. The result is stored in the same array as the original data.
        ProtectedMemory.Protect( secret, MemoryProtectionScope.SameLogon );

        // Decrypt the data in memory and store in the original array.
        ProtectedMemory.Unprotect( secret, MemoryProtectionScope.SameLogon );
    }
}
Imports System.Security.Cryptography

Public Class MemoryProtectionSample

    Public Shared Sub Main()
        ' Create the original data to be encrypted (The data length should be a multiple of 16).
        Dim secret As Byte() = {1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}

        ' Encrypt the data in memory. The result is stored in the same array as the original data.
        ProtectedMemory.Protect(secret, MemoryProtectionScope.SameLogon)

        ' Decrypt the data in memory and store in the original array.
        ProtectedMemory.Unprotect(secret, MemoryProtectionScope.SameLogon)

    End Sub
End Class

Comentarios

Este método se puede usar para descifrar datos en la memoria cifrada mediante el Protect método .

La compatibilidad con este método está disponible en los sistemas operativos Windows XP y versiones posteriores.

Se aplica a