RSACryptoServiceProvider.UseMachineKeyStore プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > RSACryptoServiceProvider.UseMachineKeyStore プロパティの意味・解説 

RSACryptoServiceProvider.UseMachineKeyStore プロパティ

ユーザー プロファイル ストア代わりにコンピュータキー ストアキー永続化する必要があるかどうかを示す値を取得または設定します

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

Public Shared Property UseMachineKeyStore
 As Boolean
Dim value As Boolean

value = RSACryptoServiceProvider.UseMachineKeyStore

RSACryptoServiceProvider.UseMachineKeyStore = value
public static bool UseMachineKeyStore
 { get; set; }
public:
static property bool UseMachineKeyStore {
    bool get ();
    void set (bool value);
}
/** @property */
public static boolean get_UseMachineKeyStore
 ()

/** @property */
public static void set_UseMachineKeyStore
 (boolean value)
public static function get
 UseMachineKeyStore () : boolean

public static function set
 UseMachineKeyStore (value : boolean)

プロパティ
キーコンピュータキー ストア永続化する必要がある場合trueそれ以外場合false

解説解説
使用例使用例

RSACryptoServiceProvider オブジェクト作成し静的UseMachineKeyStore プロパティ設定してユーザー プロファイル キー ストア代わりにコンピュータキー ストア使用するコード例次に示します

Imports System.Security.Cryptography

Module RSACSPExample

    Sub Main()

        Dim KeyContainerName As String
 = "MyKeyContainer"

        'Set the static UseMachineKeyStore property to
        'use the machine key store instead of the user
        'profile key store.  All code in the current 
        'application domain will use this setting.
        RSACryptoServiceProvider.UseMachineKeyStore = True

        'Create a new key and persist it in 
        'the key container.  
        RSAPersistKeyInCSP(KeyContainerName)

        'Delete the key from the key container.
        RSADeleteKeyInCSP(KeyContainerName)
    End Sub


    Sub RSAPersistKeyInCSP(ByVal ContainerName
 As String)
        Try
            ' Create a new instance of CspParameters.  Pass
            ' 13 to specify a RSA container or 1 to specify
            ' an RSA container.  The default is 1.
            Dim cspParams As New
 CspParameters

            ' Specify the container name using the passed variable.
            cspParams.KeyContainerName = ContainerName

            'Create a new instance of RSACryptoServiceProvider to generate
            'a new key pair.  Pass the CspParameters class to persist
 the 
            'key in the container.  The PersistKeyInCsp property is
 True by 
            'default, allowing the key to be persisted. 
            Dim RSAalg As New
 RSACryptoServiceProvider(cspParams)

            'Indicate that the key was persisted.
            Console.WriteLine("The RSA key was persisted in the
 container, ""{0}"".",
 ContainerName)
        Catch e As CryptographicException
            Console.WriteLine(e.Message)
        End Try
    End Sub


    Sub RSADeleteKeyInCSP(ByVal ContainerName
 As String)
        Try
            ' Create a new instance of CspParameters.  Pass
            ' 13 to specify a RSA container or 1 to specify
            ' an RSA container.  The default is 1.
            Dim cspParams As New
 CspParameters

            ' Specify the container name using the passed variable.
            cspParams.KeyContainerName = ContainerName

            'Create a new instance of RSACryptoServiceProvider. 
            'Pass the CspParameters class to use the 
            'key in the container.
            Dim RSAalg As New
 RSACryptoServiceProvider(cspParams)

            'Explicitly set the PersistKeyInCsp property to False
            'to delete the key entry in the container.
            RSAalg.PersistKeyInCsp = False

            'Call Clear to release resources and delete the key from
 the container.
            RSAalg.Clear()

            'Indicate that the key was persisted.
            Console.WriteLine("The RSA key was deleted from the
 container, ""{0}"".",
 ContainerName)
        Catch e As CryptographicException
            Console.WriteLine(e.Message)
        End Try
    End Sub

End Module
using System;
using System.Security.Cryptography;

class RSACSPSample
{

    static void Main()
    {

        string KeyContainerName = "MyKeyContainer";

        //Set the static UseMachineKeyStore property to
        //use the machine key store instead of the user
        //profile key store.  All code in the current 
        //application domain will use this setting.
        RSACryptoServiceProvider.UseMachineKeyStore = true;

        //Create a new key and persist it in 
        //the key container.  
        RSAPersistKeyInCSP(KeyContainerName);

        //Delete the key from the key container.
        RSADeleteKeyInCSP(KeyContainerName);
    }

    public static void RSAPersistKeyInCSP(string
 ContainerName)
    {
        try
        {
            // Create a new instance of CspParameters.  Pass
            // 13 to specify a RSA container or 1 to specify
            // an RSA container.  The default is 1.
            CspParameters cspParams = new CspParameters();

            // Specify the container name using the passed variable.
            cspParams.KeyContainerName = ContainerName;

            //Create a new instance of RSACryptoServiceProvider to generate
            //a new key pair.  Pass the CspParameters class to persist
 the 
            //key in the container.  The PersistKeyInCsp property is
 true by 
            //default, allowing the key to be persisted. 
            RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider(cspParams);

          

            //Indicate that the key was persisted.
            Console.WriteLine("The RSA key was persisted in
 the container, \"{0}\".", ContainerName);
        }
        catch(CryptographicException e)
        {
            Console.WriteLine(e.Message);

        }
    }

    public static void RSADeleteKeyInCSP(string
 ContainerName)
    {
        try
        {
            // Create a new instance of CspParameters.  Pass
            // 13 to specify a RSA container or 1 to specify
            // an RSA container.  The default is 1.
            CspParameters cspParams = new CspParameters();

            // Specify the container name using the passed variable.
            cspParams.KeyContainerName = ContainerName;

            //Create a new instance of RSACryptoServiceProvider. 
            //Pass the CspParameters class to use the 
            //key in the container.
            RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider(cspParams);

            //Explicitly set the PersistKeyInCsp property to false
            //to delete the key entry in the container.
            RSAalg.PersistKeyInCsp = false;

            //Call Clear to release resources and delete the key from
 the container.
            RSAalg.Clear();

            //Indicate that the key was persisted.
            Console.WriteLine("The RSA key was deleted from the container, \"{0}\".",
 ContainerName);
        }
        catch(CryptographicException e)
        {
            Console.WriteLine(e.Message);

        }
    }
}
using namespace System;
using namespace System::Security::Cryptography;
void RSAPersistKeyInCSP( String^ ContainerName )
{
   try
   {
      
      // Create a new instance of CspParameters.  Pass
      // 13 to specify a RSA container or 1 to specify
      // an RSA container.  The default is 1.
      CspParameters^ cspParams = gcnew CspParameters;
      
      // Specify the container name using the passed variable.
      cspParams->KeyContainerName = ContainerName;
      
      //Create a new instance of RSACryptoServiceProvider to generate
      //a new key pair.  Pass the CspParameters class to persist the
 
      //key in the container.  The PersistKeyInCsp property is true
 by 
      //default, allowing the key to be persisted. 
      RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider( cspParams
 );
      
      //Indicate that the key was persisted.
      Console::WriteLine( "The RSA key was persisted in the
 container, \"{0}\".", ContainerName );
   }
   catch ( CryptographicException^ e ) 
   {
      Console::WriteLine( e->Message );
   }

}

void RSADeleteKeyInCSP( String^ ContainerName )
{
   try
   {
      
      // Create a new instance of CspParameters.  Pass
      // 13 to specify a RSA container or 1 to specify
      // an RSA container.  The default is 1.
      CspParameters^ cspParams = gcnew CspParameters;
      
      // Specify the container name using the passed variable.
      cspParams->KeyContainerName = ContainerName;
      
      //Create a new instance of RSACryptoServiceProvider. 
      //Pass the CspParameters class to use the 
      //key in the container.
      RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider( cspParams
 );
      
      //Explicitly set the PersistKeyInCsp property to false
      //to delete the key entry in the container.
      RSAalg->PersistKeyInCsp = false;
      
      //Call Clear to release resources and delete the key from the
 container.
      RSAalg->Clear();
      
      //Indicate that the key was persisted.
      Console::WriteLine( "The RSA key was deleted from the container, \"{0}\".",
 ContainerName );
   }
   catch ( CryptographicException^ e ) 
   {
      Console::WriteLine( e->Message );
   }

}

int main()
{
   String^ KeyContainerName = "MyKeyContainer";
   
   //Set the static UseMachineKeyStore property to
   //use the machine key store instead of the user
   //profile key store.  All code in the current 
   //application domain will use this setting.
   RSACryptoServiceProvider::UseMachineKeyStore = true;
   
   //Create a new key and persist it in 
   //the key container.  
   RSAPersistKeyInCSP( KeyContainerName );
   
   //Delete the key from the key container.
   RSADeleteKeyInCSP( KeyContainerName );
}

import System.*;
import System.Security.Cryptography.*;

class RSACSPSample
{
    public static void main(String
 args[])
    {
        String keyContainerName = "MyKeyContainer";
        //Set the static UseMachineKeyStore property to
        //use the machine key store instead of the user
        //profile key store.  All code in the current 
        //application domain will use this setting.
        RSACryptoServiceProvider.set_UseMachineKeyStore(true);
        //Create a new key and persist it in 
        //the key container.  
        RSAPersistKeyInCSP(keyContainerName);
        //Delete the key from the key container.
        RSADeleteKeyInCSP(keyContainerName);
    } //main

    public static void RSAPersistKeyInCSP(String
 containerName)
    {
        try {
            // Create a new instance of CspParameters.  Pass
            // 13 to specify a RSA container or 1 to specify
            // an RSA container.  The default is 1.
            CspParameters cspParams = new CspParameters();
            // Specify the container name using the passed variable.
            cspParams.KeyContainerName = containerName;
            //Create a new instance of RSACryptoServiceProvider to generate
            //a new key pair.  Pass the CspParameters class to persist
 the 
            //key in the container.  The PersistKeyInCsp property is
 true by 
            //default, allowing the key to be persisted. 
            RSACryptoServiceProvider rsaAlg = new RSACryptoServiceProvider(
                cspParams);
            //Indicate that the key was persisted.
            Console.WriteLine("The RSA key was persisted in
 the container, " 
                + "\"{0}\".", containerName);
        }
        catch (CryptographicException e) {
            Console.WriteLine(e.get_Message());
        }
    } //RSAPersistKeyInCSP

    public static void RSADeleteKeyInCSP(String
 containerName)
    {
        try {
            // Create a new instance of CspParameters.  Pass
            // 13 to specify a RSA container or 1 to specify
            // an RSA container.  The default is 1.
            CspParameters cspParams = new CspParameters();
            // Specify the container name using the passed variable.
            cspParams.KeyContainerName = containerName;
            //Create a new instance of RSACryptoServiceProvider. 
            //Pass the CspParameters class to use the 
            //key in the container.
            RSACryptoServiceProvider rsaAlg = 
                new RSACryptoServiceProvider(cspParams);
            //Explicitly set the PersistKeyInCsp property to false
            //to delete the key entry in the container.
            rsaAlg.set_PersistKeyInCsp(false);
            //Call Clear to release resources and delete the key from
 the 
            // container.
            rsaAlg.Clear();
            //Indicate that the key was persisted.
            Console.WriteLine("The RSA key was deleted from the container, "
 
                + "\"{0}\".", containerName);
        }
        catch (CryptographicException e) {
            Console.WriteLine(e.get_Message());
        }
    } //RSADeleteKeyInCSP
} //RSACSPSample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RSACryptoServiceProvider クラス
RSACryptoServiceProvider メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス



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

辞書ショートカット

すべての辞書の索引

RSACryptoServiceProvider.UseMachineKeyStore プロパティのお隣キーワード
検索ランキング

   

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



RSACryptoServiceProvider.UseMachineKeyStore プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS