ProtectedMemory Osztály

Definíció

Módszereket biztosít a memória védelmére és védelmének megszüntetésére. Ez az osztály nem örökölhető.

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
Öröklődés
ProtectedMemory

Példák

Az alábbi példa bemutatja az adatvédelem használatát.

#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

Megjegyzések

Ez az osztály hozzáférést biztosít a Windows XP és újabb operációs rendszerekben elérhető Adatvédelmi API-hoz (DPAPI). Ez egy olyan szolgáltatás, amelyet az operációs rendszer biztosít, és nem igényel további kódtárakat. Titkosítást biztosít a memóriában lévő bizalmas adatokhoz.

Az osztály két burkolóból áll a nem felügyelt DPAPI Protect és Unprotecta . Ez a két módszer használható a memóriában lévő adatok titkosítására és visszafejtésére.

Metódusok

Name Description
Protect(Byte[], MemoryProtectionScope)

Védi a megadott adatokat.

Unprotect(Byte[], MemoryProtectionScope)

A metódussal védett memóriában lévő adatok védelmének Protect(Byte[], MemoryProtectionScope) megszüntetése.

A következőre érvényes: