ProtectedMemory.Protect(Byte[], MemoryProtectionScope) 메서드

정의

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

public:
 static void Protect(cli::array <System::Byte> ^ userData, System::Security::Cryptography::MemoryProtectionScope scope);
public static void Protect (byte[] userData, System.Security.Cryptography.MemoryProtectionScope scope);
static member Protect : byte[] * System.Security.Cryptography.MemoryProtectionScope -> unit
Public Shared Sub Protect (userData As Byte(), scope As MemoryProtectionScope)

매개 변수

userData
Byte[]

보호할 메모리의 데이터가 들어 있는 바이트 배열입니다. 배열은 16바이트의 배수가 되어야 합니다.

scope
MemoryProtectionScope

메모리 보호의 범위를 지정하는 열거형 값 중 하나입니다.

예외

userData의 길이가 16바이트 또는 16바이트의 배수가 아닌 경우

운영 체제에서 이 메서드를 지원하지 않는 경우. 이 메서드는 Windows 2000 이상의 운영 체제에서만 사용할 수 있습니다.

userData이(가) null인 경우

예제

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

#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

설명

메모리에서 데이터를 보호 하기 위해이 메서드를 사용할 수 있습니다. 메서드는 데이터의 복사본을 만들지 않습니다 하지만 바이트 배열을 내부에서 암호화는 참고 합니다. userData 매개 변수 16 바이트 길이 또는 16 바이트의 배수 여야 합니다.

이 메서드에 대 한 지원은 Windows XP 및 이후 운영 체제에서 사용할 수 있습니다.

적용 대상