JavaTM 2 Platform
Standard Ed. 6

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

构造方法摘要
protected KeyStore.Builder()
          构造新的 Builder。
 
方法摘要
abstract  KeyStore getKeyStore()
          返回此对象描述的 KeyStore。
abstract  KeyStore.ProtectionParameter getProtectionParameter(String alias)
          返回应该用来获取具有给定别名的 Entry 的 ProtectionParameters。
static KeyStore.Builder newInstance(KeyStore keyStore, KeyStore.ProtectionParameter protectionParameter)
          返回封装给定 KeyStore 的新 Builder。
static KeyStore.Builder newInstance(String type, Provider provider, File file, KeyStore.ProtectionParameter protection)
          返回新的 Builder 对象。
static KeyStore.Builder newInstance(String type, Provider provider, KeyStore.ProtectionParameter protection)
          返回新的 Builder 对象。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

KeyStore.Builder

protected KeyStore.Builder()
构造新的 Builder。

方法详细信息

getKeyStore

public abstract KeyStore getKeyStore()
                              throws KeyStoreException
返回此对象描述的 KeyStore。

抛出:
KeyStoreException - 如果操作期间出现错误,例如,如果 KeyStore 不能被实例化或加载。

getProtectionParameter

public abstract KeyStore.ProtectionParameter getProtectionParameter(String alias)
                                                             throws KeyStoreException
返回应该用来获取具有给定别名的 Entry 的 ProtectionParameters。在调用此方法前必须调用 getKeyStore 方法。

参数:
alias - KeyStore 项的别名
返回:
应该用来获取具有给定别名的 Entry 的 ProtectionParameters。
抛出:
NullPointerException - 如果 alias 为 null
KeyStoreException - 如果操作期间发生错误
IllegalStateException - 如果调用此方法前没有调用 getKeyStore 方法

newInstance

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

如果一个现有的 KeyStore 对象需要和基于 Builder 的 APIs 一起使用,则此方法很有用。

参数:
keyStore - 将被封装的 KeyStore
protectionParameter - 用来保护 KeyStore 项的 ProtectionParameter
返回:
新的 Builder 对象
抛出:
NullPointerException - 如果 keyStore 或 protectionParameters 为 null
IllegalArgumentException - 如果 keyStore 没有被初始化

newInstance

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

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

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

根据 provider(如果非 null)初始化 KeyStore。否则,将搜索所有安装的提供者。

调用 getProtectionParameter() 将返回 PasswordProtection 对象,该对象封装用来调用 load 方法的密码。

注意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(String type,
                                           Provider provider,
                                           KeyStore.ProtectionParameter protection)
返回新的 Builder 对象。

每次对返回的 builder 调用 getKeyStore() 方法将返回新的 type 类型的 KeyStore 对象。使用封装 protectionLoadStoreParameter 调用其 load() 方法。

根据 provider(如果非 null)初始化 KeyStore。否则,将搜索所有安装的提供者。

调用 getProtectionParameter() 将返回 protection

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

参数:
type - 将构造的 KeyStore 类型
provider - 根据其实例化 KeyStore 的提供者(或 null)
protection - 保护 Keystore 的 ProtectionParameter
返回:
新的 Builder 对象
抛出:
NullPointerException - 如果 type 或 protection 为 null

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only