Share via


ProtectedMemory 클래스

정의

메모리를 보호하거나 보호 해제하는 메서드를 제공합니다. 이 클래스는 상속될 수 없습니다.

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
상속
ProtectedMemory

예제

다음 예제에서는 데이터 보호를 사용 하는 방법을 보여 줍니다.

#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

설명

이 클래스에는 DPAPI 데이터 보호 API () Windows XP 및 이후 운영 체제에서 사용할 수 있는 액세스를 제공합니다. 추가 라이브러리가 필요 하지 않습니다 하 고 운영 체제에서 제공 되는 서비스입니다. 중요 한 데이터를 메모리에 대 한 암호화를 제공합니다.

클래스는 관리 되지 않는 DPAPI에 대 한 두 래퍼 이루어져 ProtectUnprotect입니다. 이 두 메서드는 메모리에 대 한 데이터 암호화 및 해독에 사용할 수 있습니다.

메서드

Protect(Byte[], MemoryProtectionScope)

지정한 데이터를 보호합니다.

Unprotect(Byte[], MemoryProtectionScope)

Protect(Byte[], MemoryProtectionScope) 메서드를 사용하여 보호된 메모리에 있는 데이터의 보호를 해제합니다.

적용 대상