模块 java.base

类 KeyStore.Builder

java.lang.Object
java.security.KeyStore.Builder
封闭类:
KeyStore

public abstract static class KeyStore.Builder extends Object
待实例化的 KeyStore 对象的描述。

此类的实例封装了实例化和初始化 KeyStore 对象所需的信息。当调用 getKeyStore() 方法时会触发该过程。

这使得将配置与 KeyStore 对象创建分离成为可能,例如,将密码提示延迟到需要时。

自从:
1.5
参见:
  • 构造方法详细信息

    • 建设者

      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 - 如果别名是 null
      KeyStoreException - 如果在操作过程中发生错误
      IllegalStateException - 如果在调用此方法之前未调用 getKeyStore 方法
    • newInstance

      public static KeyStore.Builder  newInstance(KeyStore  keyStore, KeyStore.ProtectionParameter  protectionParameter)
      返回封装给定 KeyStore 的新 Builder。返回对象的getKeyStore()方法会返回keyStoregetProtectionParameter()方法会返回protectionParameters

      如果现有的 KeyStore 对象需要与基于构建器的 API 一起使用,这将很有用。

      参数:
      keyStore - 要封装的 KeyStore
      protectionParameter - ProtectionParameter 用于保护 KeyStore 条目
      返回:
      一个新的 Builder 对象
      抛出:
      NullPointerException - 如果 keyStoreprotectionParameternull
      IllegalArgumentException - 如果 keyStore 尚未初始化
    • newInstance

      public static KeyStore.Builder  newInstance(String  type, Provider  provider, File  file, KeyStore.ProtectionParameter  protection)
      返回一个新的 Builder 对象。

      对返回的构建器的 getKeyStore() 方法的第一次调用将创建一个 type 类型的 KeyStore 并调用其 load() 方法。 inputStream 参数是从 file 构建的。如果 protection 是一个 PasswordProtection ,则通过调用 getPassword 方法获取密码。否则,如果 protectionCallbackHandlerProtection,则通过调用 CallbackHandler 获取密码。

      getKeyStore() 的后续调用返回与初始调用相同的对象。如果初始调用失败并返回 KeyStoreException ,后续调用也会抛出 KeyStoreException

      如果 KeyStore 非空,则从 provider 实例化。否则,将搜索所有已安装的提供程序。

      调用 getProtectionParameter() 将返回一个 PasswordProtection 对象,其中封装了用于调用 load 方法的密码。

      Note getKeyStore() 方法在调用此方法的代码的 AccessControlContext 中执行。

      参数:
      type - 要构造的 KeyStore 的类型
      provider - 从中实例化 KeyStore 的提供程序(或 null
      file - 包含 KeyStore 数据的文件
      protection - ProtectionParameter 保护 KeyStore 数据
      返回:
      一个新的 Builder 对象
      抛出:
      NullPointerException - 如果类型、文件或保护是 null
      IllegalArgumentException - 如果保护不是 PasswordProtection 或 CallbackHandlerProtection 的实例;或者如果文件不存在或不引用普通文件
    • newInstance

      public static KeyStore.Builder  newInstance(File  file, KeyStore.ProtectionParameter  protection)
      返回一个新的 Builder 对象。

      对返回的构建器的 getKeyStore() 方法的第一次调用将使用 file 创建一个 KeyStore 来检测密钥库类型,然后调用其 load() 方法。它使用与 KeyStore.getInstance(File, LoadStoreParameter) 中描述的相同算法来确定密钥库类型。 inputStream 参数是从 file 构建的。如果 protection 是一个 PasswordProtection ,则通过调用 getPassword 方法获取密码。否则,如果 protectionCallbackHandlerProtection,则通过调用 CallbackHandler 获取密码。

      getKeyStore() 的后续调用返回与初始调用相同的对象。如果初始调用失败并返回 KeyStoreException ,后续调用也会抛出 KeyStoreException

      调用 getProtectionParameter() 将返回一个 PasswordProtection 对象,其中封装了用于调用 load 方法的密码。

      Note getKeyStore() 方法在调用此方法的代码的 AccessControlContext 中执行。

      参数:
      file - 包含 KeyStore 数据的文件
      protection - ProtectionParameter 保护 KeyStore 数据
      返回:
      一个新的 Builder 对象
      抛出:
      NullPointerException - 如果文件或保护是 null
      IllegalArgumentException - 如果保护不是 PasswordProtection 或 CallbackHandlerProtection 的实例;或者如果文件不存在或不引用普通文件
      自从:
      9
    • newInstance

      public static KeyStore.Builder  newInstance(String  type, Provider  provider, KeyStore.ProtectionParameter  protection)
      返回一个新的 Builder 对象。

      每次调用返回的构建器上的 getKeyStore() 方法都会返回一个新的 KeyStore 类型为 type 的对象。它的 load() 方法是使用封装 protectionLoadStoreParameter 调用的。

      如果 KeyStore 非空,则从 provider 实例化。否则,将搜索所有已安装的提供程序。

      调用 getProtectionParameter() 将返回 protection

      Note getKeyStore() 方法在调用此方法的代码的 AccessControlContext 中执行。

      参数:
      type - 要构造的 KeyStore 的类型
      provider - 从中实例化 KeyStore 的提供程序(或 null
      protection - ProtectionParameter 保护 Keystore
      返回:
      一个新的 Builder 对象
      抛出:
      NullPointerException - 如果类型或保护是 null