モジュール java.base
パッケージ java.security

クラスKeyStore.Builder

java.lang.Object
java.security.KeyStore.Builder
含まれているクラス:
KeyStore

public abstract static class KeyStore.Builder
extends Object
インスタンス化すべきKeyStoreオブジェクトを記述したクラスです。

このクラスのインスタンスは、KeyStoreオブジェクトのインスタンス化と初期化に必要な情報をカプセル化します。 getKeyStore()メソッドを呼び出すと、この処理が起動されます。

これにより、KeyStoreオブジェクト作成から構成を分離することができ、必要になるまでパスワード・プロンプトを遅延化させることなどが可能となります。

導入されたバージョン:
1.5
関連項目:
KeyStore, KeyStoreBuilderParameters
  • コンストラクタの詳細

    • Builder

      protected Builder()
      新しいBuilderを構築します。
  • メソッドの詳細

    • getKeyStore

      public abstract KeyStore getKeyStore() throws KeyStoreException
      このオブジェクトが記述するKeyStoreを返します。
      戻り値:
      このオブジェクトが記述するKeyStore
      例外:
      KeyStoreException - 処理中にエラーが発生した場合(KeyStoreのインスタンス化またはロードに失敗した場合など)
    • getProtectionParameter

      public abstract KeyStore.ProtectionParameter getProtectionParameter​(String alias) throws KeyStoreException
      指定された別名のEntryを取得する際に使用すべきProtectionParameterを返します。 getKeyStoreメソッドを呼び出したあとでないと、このメソッドを呼び出せません。
      パラメータ:
      alias - KeyStoreエントリの別名
      戻り値:
      指定された別名のEntryを取得する際に使用すべきProtectionParameter。
      例外:
      NullPointerException - aliasがnullである場合
      KeyStoreException - 処理中にエラーが発生した場合
      IllegalStateException - このメソッドを呼び出す前にgetKeyStoreメソッドを呼び出していない場合
    • newInstance

      public static KeyStore.Builder newInstance​(KeyStore keyStore, KeyStore.ProtectionParameter protectionParameter)
      指定されたKeyStoreをカプセル化する新しいBuilderを返します。 返されたオブジェクトのgetKeyStore()メソッドはkeyStoreを返し、getProtectionParameter()メソッドはprotectionParametersを戻します。

      このメソッドは、BuilderベースのAPIで既存のKeyStoreオブジェクトを使用する必要がある場合に便利です。

      パラメータ:
      keyStore - カプセル化するKeyStore
      protectionParameter - KeyStoreエントリの保護に使用するProtectionParameter
      戻り値:
      新しいBuilderオブジェクト
      例外:
      NullPointerException - keyStoreまたはprotectionParameterのいずれかがnullである場合
      IllegalArgumentException - keyStoreが初期化されていない場合
    • newInstance

      public static KeyStore.Builder newInstance​(String type, Provider provider, File file, KeyStore.ProtectionParameter protection)
      新しいBuilderオブジェクトを返します。

      返されたビルダー上での初回のgetKeyStore()メソッドの呼出しでは、type型のKeyStoreが作成され、そのload()メソッドが呼び出されます。 inputStream引数はfileに基づいて構築されます。 protectionPasswordProtectionである場合、パスワードを取得するにはgetPasswordメソッドを呼び出します。 protectionCallbackHandlerProtectionである場合、パスワードを取得するにはCallbackHandlerを呼び出します。

      後続のgetKeyStore()呼出しでは、初回の呼出し時と同じオブジェクトが返されます。 KeyStoreExceptionで初期呼び出しが失敗した場合、後続の呼び出しもKeyStoreExceptionをスローします。

      providerがnullでない場合、そのプロバイダからKeyStoreがインスタンス化されます。 そうでない場合は、インストールされたすべてのプロバイダが検索されます。

      getProtectionParameter()を呼び出すと、loadメソッドの呼出し時に使用されたパスワードをカプセル化したPasswordProtectionオブジェクトが返されます。

      getKeyStore()メソッドは、このメソッドを呼び出しているコードのAccessControlContext内で実行されることに注意してください

      パラメータ:
      type - 構築するKeyStoreの型
      provider - KeyStoreをインスタンス化する際の基となるプロバイダまたはnull
      file - KeyStoreデータが格納されたFile
      protection - KeyStoreデータを保護するProtectionParameter
      戻り値:
      新しいBuilderオブジェクト
      例外:
      NullPointerException - type、file、またはprotectionのいずれかがnullである場合
      IllegalArgumentException - protectionがPasswordProtection、CallbackHandlerProtectionのどちらのインスタンスでもない場合、またはfileが存在しないか、通常のファイルを参照していない場合
    • newInstance

      public static KeyStore.Builder newInstance​(File file, KeyStore.ProtectionParameter protection)
      新しいBuilderオブジェクトを返します。

      返されたビルダーのgetKeyStore()メソッドへの最初の呼び出しでは、fileを使用してKeyStoreを作成し、キーストア型を検出してからload()メソッドを呼び出します。 KeyStore.getInstance(File, LoadStoreParameter)で説明されているように、同じアルゴリズムを使用してキーストアの型を判別します。 inputStream引数はfileに基づいて構築されます。 protectionPasswordProtectionである場合、パスワードを取得するにはgetPasswordメソッドを呼び出します。 protectionCallbackHandlerProtectionである場合、パスワードを取得するにはCallbackHandlerを呼び出します。

      後続のgetKeyStore()呼出しでは、初回の呼出し時と同じオブジェクトが返されます。 KeyStoreExceptionで初期呼び出しが失敗した場合、後続の呼び出しもKeyStoreExceptionをスローします。

      getProtectionParameter()を呼び出すと、loadメソッドの呼出し時に使用されたパスワードをカプセル化したPasswordProtectionオブジェクトが返されます。

      getKeyStore()メソッドは、このメソッドを呼び出しているコードのAccessControlContext内で実行されることに注意してください

      パラメータ:
      file - KeyStoreデータが格納されたFile
      protection - KeyStoreデータを保護するProtectionParameter
      戻り値:
      新しいBuilderオブジェクト
      例外:
      NullPointerException - ファイルまたは保護がnullの場合
      IllegalArgumentException - protectionがPasswordProtection、CallbackHandlerProtectionのどちらのインスタンスでもない場合、またはfileが存在しないか、通常のファイルを参照していない場合
      導入されたバージョン:
      9
    • newInstance

      public static KeyStore.Builder newInstance​(String type, Provider provider, KeyStore.ProtectionParameter protection)
      新しいBuilderオブジェクトを返します。

      返されたビルダー上でgetKeyStore()メソッドを呼び出すたびに、型typeの新しいKeyStoreオブジェクトが返されます。 そのload()メソッドは、protectionをカプセル化したLoadStoreParameterを使用して呼び出されます。

      providerがnullでない場合、そのプロバイダからKeyStoreがインスタンス化されます。 そうでない場合は、インストールされたすべてのプロバイダが検索されます。

      getProtectionParameter()を呼び出すと、protectionを返します。

      getKeyStore()メソッドは、このメソッドを呼び出しているコードのAccessControlContext内で実行されることに注意してください

      パラメータ:
      type - 構築するKeyStoreの型
      provider - KeyStoreをインスタンス化する際の基となるプロバイダまたはnull
      protection - キーストアを保護するProtectionParameter
      戻り値:
      新しいBuilderオブジェクト
      例外:
      NullPointerException - type、protectionのいずれかがnullである場合