Share via


ProtectedMemory Sınıf

Tanım

Belleği korumaya ve korumasını kaldırmaya yönelik yöntemler sağlar. Bu sınıf devralınamaz.

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

Örnekler

Aşağıdaki örnekte veri korumanın nasıl kullanılacağı gösterilmektedir.

#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

Açıklamalar

Bu sınıf, Windows XP ve sonraki işletim sistemlerinde kullanılabilen Veri Koruma API'sine (DPAPI) erişim sağlar. Bu, işletim sistemi tarafından sağlanan ve ek kitaplıklar gerektirmeyen bir hizmettir. Bellekteki hassas veriler için şifreleme sağlar.

sınıfı, Protect yönetilmeyen DPAPI ve Unprotectiçin iki sarmalayıcıdan oluşur. Bu iki yöntem, bellekteki verileri şifrelemek ve şifresini çözmek için kullanılabilir.

Yöntemler

Protect(Byte[], MemoryProtectionScope)

Belirtilen verileri korur.

Unprotect(Byte[], MemoryProtectionScope)

yöntemi kullanılarak korunan bellekteki verilerin korumasını kaldırıyor Protect(Byte[], MemoryProtectionScope) .

Şunlara uygulanır