ProtectedMemory Klas

Definitie

Biedt methoden voor het beveiligen en opheffen van het geheugen. Deze klasse kan niet worden overgenomen.

public ref class ProtectedMemory sealed
public ref class ProtectedMemory abstract sealed
public sealed class ProtectedMemory
public static class ProtectedMemory
type ProtectedMemory = class
Public NotInheritable Class ProtectedMemory
Public Class ProtectedMemory
Overname
ProtectedMemory

Voorbeelden

In het volgende voorbeeld ziet u hoe u gegevensbeveiliging gebruikt.

#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

Opmerkingen

Deze klasse biedt toegang tot de Data Protection-API (DPAPI) die beschikbaar is in de Windows XP en latere besturingssystemen. Dit is een service die wordt geleverd door het besturingssysteem en waarvoor geen extra bibliotheken nodig zijn. Het biedt versleuteling voor gevoelige gegevens in het geheugen.

De klasse bestaat uit twee wrappers voor de onbeheerde DPAPI Protect en Unprotect. Deze twee methoden kunnen worden gebruikt voor het versleutelen en ontsleutelen van gegevens in het geheugen.

Methoden

Name Description
Protect(Byte[], MemoryProtectionScope)

Beveiligt de opgegeven gegevens.

Unprotect(Byte[], MemoryProtectionScope)

Hiermee maakt u de beveiliging van gegevens in het geheugen op die zijn beveiligd met behulp van de Protect(Byte[], MemoryProtectionScope) methode.

Van toepassing op