MemoryProtectionScope Wyliczenie

Definicja

Określa zakres ochrony pamięci, który ma być stosowany przez metodę Protect(Byte[], MemoryProtectionScope) .

public enum class MemoryProtectionScope
public enum MemoryProtectionScope
type MemoryProtectionScope = 
Public Enum MemoryProtectionScope
Dziedziczenie
MemoryProtectionScope

Pola

CrossProcess 1

Cały kod w dowolnym procesie może wyłączyć ochronę pamięci chronionej Protect(Byte[], MemoryProtectionScope) przy użyciu metody .

SameLogon 2

Tylko kod uruchomiony w tym samym kontekście użytkownika co kod, który nazwał metodę Protect(Byte[], MemoryProtectionScope) , może wyłączyć ochronę pamięci.

SameProcess 0

Tylko kod uruchomiony w tym samym procesie co kod, który nazwał metodę Protect(Byte[], MemoryProtectionScope) , może wyłączyć ochronę pamięci.

Przykłady

W poniższym przykładzie kodu pokazano, jak korzystać z ochrony danych.

#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

Uwagi

To wyliczenie jest używane z metodami Protect i Unprotect w celu ochrony danych w pamięci.

Dotyczy