ProtectedMemory クラス
アセンブリ: System.Security (system.security.dll 内)
構文
解説
このクラスには、Microsoft Windows XP 以降のオペレーティング システムで利用できるデータ保護 API (DPAPI) へのアクセス機能が用意されています。これは、オペレーティング システムにより提供されるサービスです。追加のライブラリは必要ありません。メモリ内の重要情報の暗号化を実現します。
このクラスはアンマネージ DPAPI の 2 つのラッパー、Protect および Unprotect で構成されます。この 2 つのメソッドを使用して、メモリ内のデータの暗号化と復号化を行うことができます。
using System; using System.Security.Cryptography; public class MemoryProtectionSample { // Create aditional entropy for use with the Protect method. static byte [] s_aditionalEntropy = { 9, 8, 7, 6, 5 }; 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 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.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 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 ); }
import System.*; import System.Security.Cryptography.*; public class MemoryProtectionSample { // Create aditional entropy for use with the Protect method. private static ubyte sAditionalEntropy[] = { 9, 8, 7, 6, 5 }; public static void main(String args[]) { // Create the original data to be encrypted (The data length should // be a multiple of 16). ubyte 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 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); } //main } //MemoryProtectionSample
System.Security.Cryptography.ProtectedMemory
プラットフォーム
Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- ProtectedMemory クラスのページへのリンク