ProtectedMemory Klasse

Definition

Stellt Methoden bereit, die den Arbeitsspeicher schützen bzw. den Schutz des Arbeitsspeichers aufheben. Diese Klasse kann nicht vererbt werden.

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
Vererbung
ProtectedMemory

Beispiele

Im folgenden Beispiel wird gezeigt, wie Der Datenschutz verwendet wird.

#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

Hinweise

Diese Klasse bietet Zugriff auf die Data Protection API (DPAPI), die in den Windows XP und späteren Betriebssystemen verfügbar ist. Dies ist ein Dienst, der vom Betriebssystem bereitgestellt wird und keine zusätzlichen Bibliotheken erfordert. Es bietet Verschlüsselung für vertrauliche Daten im Arbeitsspeicher.

Die Klasse besteht aus zwei Wrappern für die nicht verwaltete DPAPI und Protect Unprotect. Diese beiden Methoden können verwendet werden, um Daten im Arbeitsspeicher zu verschlüsseln und zu entschlüsseln.

Methoden

Protect(Byte[], MemoryProtectionScope)

Schützt die angegebenen Daten.

Unprotect(Byte[], MemoryProtectionScope)

Hebt nicht den Schutz von Daten im Arbeitsspeicher auf, die mit der Protect(Byte[], MemoryProtectionScope)-Methode geschützt wurden.

Gilt für