英語で読む

次の方法で共有


MemoryProtectionScope 列挙型

定義

Protect(Byte[], MemoryProtectionScope) メソッドにより適用されるメモリ保護のスコープを指定します。

C#
public enum MemoryProtectionScope
継承
MemoryProtectionScope

フィールド

名前 説明
CrossProcess 1

Protect(Byte[], MemoryProtectionScope) メソッドを使用して保護されていたメモリの保護を、任意のプロセスのすべてのコードで解除できます。

SameLogon 2

メモリの保護を解除できるのは、Protect(Byte[], MemoryProtectionScope) メソッドを呼び出したコードと同じユーザー コンテキストで実行されるコードのみです。

SameProcess 0

メモリの保護を解除できるのは、Protect(Byte[], MemoryProtectionScope) メソッドを呼び出したコードと同じプロセスで実行されるコードのみです。

次のコード例は、データ保護の使用方法を示しています。

C#
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 );
    }
}

注釈

この列挙は、 メソッドと Unprotect メソッドと共Protectに使用され、メモリ内のデータを保護します。

適用対象

製品 バージョン
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1