Share via


MemoryProtectionScope Enum

Definisi

Menentukan cakupan perlindungan memori yang akan diterapkan oleh Protect(Byte[], MemoryProtectionScope) metode .

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

Bidang

CrossProcess 1

Semua kode dalam proses apa pun dapat membuka proteksi memori yang dilindungi menggunakan metode .Protect(Byte[], MemoryProtectionScope)

SameLogon 2

Hanya kode yang berjalan dalam konteks pengguna yang sama dengan kode yang disebut Protect(Byte[], MemoryProtectionScope) metode yang dapat membuka proteksi memori.

SameProcess 0

Hanya kode yang berjalan dalam proses yang sama dengan kode yang disebut metode yang Protect(Byte[], MemoryProtectionScope) dapat membuka proteksi memori.

Contoh

Contoh kode berikut menunjukkan cara menggunakan perlindungan data.

#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

Keterangan

Enumerasi ini digunakan dengan Protect metode dan Unprotect untuk melindungi data dalam memori.

Berlaku untuk