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

注釈

このクラスは、Windows XP 以降のオペレーティング システムで使用できる Data Protection API (DPAPI) へのアクセスを提供します。 これは、オペレーティング システムによって提供され、追加のライブラリを必要としないサービスです。 メモリ内の機密データの暗号化を提供します。

このクラスは、アンマネージド DPAPI 用の 2 つのラッパーで構成され、Protect.Unprotect これら 2 つの方法を使用して、メモリ内のデータの暗号化と暗号化解除を行うことができます。

メソッド

Protect(Byte[], MemoryProtectionScope)

指定されたデータを保護します。

Unprotect(Byte[], MemoryProtectionScope)

Protect(Byte[], MemoryProtectionScope) メソッドを使用して保護されたメモリ内データの保護を解除します。

適用対象