ProtectedDataとは? わかりやすく解説

ProtectedData クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

データ保護保護解除のためのメソッド提供します。このクラス継承できません。

名前空間: System.Security.Cryptography
アセンブリ: System.Security (system.security.dll 内)
構文構文

Public NotInheritable Class
 ProtectedData
Dim instance As ProtectedData
public sealed class ProtectedData
public ref class ProtectedData sealed
public final class ProtectedData
public final class ProtectedData
解説解説
使用例使用例

データ保護使用方法次のコード例示します

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 
継承階層継承階層
System.Object
  System.Security.Cryptography.ProtectedData
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ProtectedData メンバ
System.Security.Cryptography 名前空間

ProtectedData メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ProtectedData クラス
System.Security.Cryptography 名前空間

ProtectedData メンバ

データ保護保護解除のためのメソッド提供します。このクラス継承できません。

ProtectedData データ型公開されるメンバを以下の表に示します


パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ProtectedData クラス
System.Security.Cryptography 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からProtectedDataを検索した結果を表示しています。
Weblioに収録されているすべての辞書からProtectedDataを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からProtectedData を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ProtectedData」の関連用語

ProtectedDataのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ProtectedDataのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS