DataProtectionScope 列挙体
アセンブリ: System.Security (system.security.dll 内)

Public Enumeration DataProtectionScope

メンバ名 | 説明 | |
---|---|---|
CurrentUser | 保護されたデータは、現在のユーザーに関連付けられます。現在のユーザー コンテキスト下で実行されているスレッドだけがデータの保護を解除できます。 | |
LocalMachine | 保護されたデータは、コンピュータのコンテキストに関連付けられます。コンピュータ上で実行されているすべてのプロセスがデータの保護を解除できます。この列挙値は、サーバーに固有のアプリケーション (つまり、信頼のおけるユーザー以外はアクセスできないサーバー上で動作するアプリケーション) で使用されます。 |

この列挙型は、暗号化によってデータを保護するために、Protect メソッドおよび Unprotect メソッドとの組み合わせで使用されます。
注意 LocalMachine 列挙値では、複数のアカウントがデータの保護を解除できるようになります。この値は、コンピュータ上のすべてのアカウントを信頼する場合にのみ使用します。通常は、CurrentUser 値を使用してください。

using System; using System.Security.Cryptography; public class DataProtectionSample { // Create byte array for additional entropy when using Protect method. static byte [] s_aditionalEntropy = { 9, 8, 7, 6, 5 }; public static void Main() { // Create a simple byte array containing data to be encrypted. byte [] secret = { 0, 1, 2, 3, 4, 1, 2, 3, 4 }; //Encrypt the data. byte [] encryptedSecret = Protect( secret ); Console.WriteLine("The encrypted byte array is:"); PrintValues(encryptedSecret); // Decrypt the data and store in a byte array. byte [] originalData = Unprotect( encryptedSecret ); Console.WriteLine("{0}The original data is:", Environment.NewLine); PrintValues(originalData); } public static byte [] Protect( byte [] data ) { try { // Encrypt the data using DataProtectionScope.CurrentUser. The result can be decrypted // only by the same current user. return ProtectedData.Protect( data, s_aditionalEntropy, DataProtectionScope.CurrentUser ); } catch (CryptographicException e) { Console.WriteLine("Data was not encrypted. An error occurred."); Console.WriteLine(e.ToString()); return null; } } public static byte [] Unprotect( byte [] data ) { try { //Decrypt the data using DataProtectionScope.CurrentUser. return ProtectedData.Unprotect( data, s_aditionalEntropy, DataProtectionScope.CurrentUser ); } catch (CryptographicException e) { Console.WriteLine("Data was not decrypted. An error occurred."); Console.WriteLine(e.ToString()); return null; } } public static void PrintValues( Byte[] myArr ) { foreach ( Byte i in myArr ) { Console.Write( "\t{0}", i ); } Console.WriteLine(); } }
#using <System.Security.dll> using namespace System; using namespace System::Security::Cryptography; public ref class DataProtectionSample { private: // Create byte array for additional entropy when using Protect method. static array<Byte>^s_aditionalEntropy = {9,8,7,6,5}; public: static void Main() { // Create a simple byte array containing data to be encrypted. array<Byte>^secret = {0,1,2,3,4,1,2,3,4}; //Encrypt the data. array<Byte>^encryptedSecret = Protect( secret ); Console::WriteLine( "The encrypted byte array is:" ); PrintValues( encryptedSecret ); // Decrypt the data and store in a byte array. array<Byte>^originalData = Unprotect( encryptedSecret ); Console::WriteLine( "{0}The original data is:", Environment::NewLine ); PrintValues( originalData ); } static array<Byte>^ Protect( array<Byte>^data ) { try { // Encrypt the data using DataProtectionScope.CurrentUser. The result can be decrypted // only by the same current user. return ProtectedData::Protect( data, s_aditionalEntropy, DataProtectionScope::CurrentUser ); } catch ( CryptographicException^ e ) { Console::WriteLine( "Data was not encrypted. An error occurred." ); Console::WriteLine( e ); return nullptr; } } static array<Byte>^ Unprotect( array<Byte>^data ) { try { //Decrypt the data using DataProtectionScope.CurrentUser. return ProtectedData::Unprotect( data, s_aditionalEntropy, DataProtectionScope::CurrentUser ); } catch ( CryptographicException^ e ) { Console::WriteLine( "Data was not decrypted. An error occurred." ); Console::WriteLine( e ); return nullptr; } } static void PrintValues( array<Byte>^myArr ) { System::Collections::IEnumerator^ myEnum = myArr->GetEnumerator(); while ( myEnum->MoveNext() ) { Byte i = safe_cast<Byte>(myEnum->Current); Console::Write( "\t{0}", i ); } Console::WriteLine(); } }; int main() { DataProtectionSample::Main(); }
import System.*; import System.Security.Cryptography.*; public class DataProtectionSample { // Create byte array for additional entropy when using Protect method. private static ubyte sAditionalEntropy[] = { 9, 8, 7, 6, 5 }; public static void main(String args[]) { // Create a simple byte array containing data to be encrypted. ubyte secret[] = { 0, 1, 2, 3, 4, 1, 2, 3, 4 }; //Encrypt the data. ubyte encryptedSecret[] = Protect(secret); Console.WriteLine("The encrypted byte array is:"); PrintValues(encryptedSecret); // Decrypt the data and store in a byte array. ubyte originalData[] = Unprotect(encryptedSecret); Console.WriteLine("{0}The original data is:", Environment.get_NewLine()); PrintValues(originalData); } //main public static ubyte[] Protect(ubyte data[]) { try { // Encrypt the data using DataProtectionScope.CurrentUser. // The result can be decrypted only by the same current user. return ProtectedData.Protect(data, sAditionalEntropy, DataProtectionScope.CurrentUser); } catch (CryptographicException e) { Console.WriteLine("Data was not encrypted. An error occurred."); Console.WriteLine(e.ToString()); return null; } } //Protect public static ubyte[] Unprotect(ubyte data[]) { try { //Decrypt the data using DataProtectionScope.CurrentUser. return ProtectedData.Unprotect(data, sAditionalEntropy, DataProtectionScope.CurrentUser); } catch (CryptographicException e) { Console.WriteLine("Data was not decrypted. An error occurred."); Console.WriteLine(e.ToString()); return null; } } //Unprotect public static void PrintValues(ubyte myArr[]) { for (int iCtr = 0; iCtr < myArr.length; iCtr++) { ubyte i = myArr[iCtr]; Console.Write("\t{0}", System.Convert.ToString(i)); } Console.WriteLine(); } //PrintValues } //DataProtectionSample

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDataProtectionScope 列挙体を検索する場合は、下記のリンクをクリックしてください。

- DataProtectionScope 列挙体のページへのリンク