public static abstract class KeyStore.Builder
extends Object
| java.lang.Object | |
| ↳ | java.security.KeyStore.Builder |
对待实例化的KeyStore对象的描述。
此类的一个实例封装了实例化和初始化KeyStore对象所需的信息。 该过程在调用getKeyStore()方法时触发。
这样可以将配置从KeyStore对象创建中分离出来,例如延迟密码提示,直到需要为止。
Protected constructors |
|
|---|---|
KeyStore.Builder() 构建一个新的Builder。 |
|
Public methods |
|
|---|---|
abstract KeyStore |
getKeyStore() 返回此对象描述的KeyStore。 |
abstract KeyStore.ProtectionParameter |
getProtectionParameter(String alias) 返回应该用来获取具有给定别名的 |
static KeyStore.Builder |
newInstance(String type, Provider provider, KeyStore.ProtectionParameter protection) 返回一个新的Builder对象。 |
static KeyStore.Builder |
newInstance(String type, Provider provider, File file, KeyStore.ProtectionParameter protection) 返回一个新的Builder对象。 |
static KeyStore.Builder |
newInstance(KeyStore keyStore, KeyStore.ProtectionParameter protectionParameter) 返回封装给定KeyStore的新建Builder。 |
Inherited methods |
|
|---|---|
java.lang.Object
|
|
KeyStore getKeyStore ()
返回此对象描述的KeyStore。
| Returns | |
|---|---|
KeyStore |
|
| Throws | |
|---|---|
KeyStoreException |
if an error occured during the operation, for example if the KeyStore could not be instantiated or loaded |
KeyStore.ProtectionParameter getProtectionParameter (String alias)
返回应该用来获得具有给定别名的Entry的ProtectionParameters。 必须在调用此方法之前调用getKeyStore方法。
| Parameters | |
|---|---|
alias |
String: the alias of the KeyStore entry |
| Returns | |
|---|---|
KeyStore.ProtectionParameter |
the ProtectionParameters that should be used to obtain the Entry with the given alias. |
| Throws | |
|---|---|
NullPointerException |
if alias is null |
KeyStoreException |
if an error occured during the operation |
IllegalStateException |
if the getKeyStore method has not been invoked prior to calling this method |
KeyStore.Builder newInstance (String type, Provider provider, KeyStore.ProtectionParameter protection)
返回一个新的Builder对象。
对返回的构建器上的getKeyStore()方法的每次调用将返回一个类型为type的新KeyStore对象。 它的load()方法是使用封装protection的LoadStoreParameter调用的。
如果非null,KeyStore将从provider实例化。 否则,搜索所有安装的提供商。
致电 getProtectionParameter()将返回 protection 。
请注意 , getKeyStore()方法在调用此方法的代码的 AccessControlContext内执行。
| Parameters | |
|---|---|
type |
String: the type of KeyStore to be constructed |
provider |
Provider: the provider from which the KeyStore is to be instantiated (or null) |
protection |
KeyStore.ProtectionParameter: the ProtectionParameter securing the Keystore |
| Returns | |
|---|---|
KeyStore.Builder |
a new Builder object |
| Throws | |
|---|---|
NullPointerException |
if type or protection is null |
KeyStore.Builder newInstance (String type, Provider provider, File file, KeyStore.ProtectionParameter protection)
返回一个新的Builder对象。
在返回的构建器上第一次调用getKeyStore()方法将创建类型为type的KeyStore并调用其方法load() 。 inputStream参数由file 。 如果protection是PasswordProtection ,则通过调用getPassword方法获得密码。 否则,如果protection是CallbackHandlerProtection ,则通过调用CallbackHandler获取密码。
随后对getKeyStore()调用返回与初始调用相同的对象。 如果初始调用失败并出现KeyStoreException,后续调用也会抛出KeyStoreException。
如果非null,则KeyStore从provider实例化。 否则,搜索所有安装的提供商。
调用 getProtectionParameter()将返回一个封装了用于调用 load方法的密码的 PasswordProtection对象。
请注意 , getKeyStore()方法在调用此方法的代码的 AccessControlContext内执行。
| Parameters | |
|---|---|
type |
String: the type of KeyStore to be constructed |
provider |
Provider: the provider from which the KeyStore is to be instantiated (or null) |
file |
File: the File that contains the KeyStore data |
protection |
KeyStore.ProtectionParameter: the ProtectionParameter securing the KeyStore data |
| Returns | |
|---|---|
KeyStore.Builder |
a new Builder object |
| Throws | |
|---|---|
NullPointerException |
if type, file or protection is null |
IllegalArgumentException |
if protection is not an instance of either PasswordProtection or CallbackHandlerProtection; or if file does not exist or does not refer to a normal file |
KeyStore.Builder newInstance (KeyStore keyStore, KeyStore.ProtectionParameter protectionParameter)
返回封装给定KeyStore的新建Builder。 该getKeyStore()返回对象的方法将返回keyStore ,该getProtectionParameter()方法将返回protectionParameters 。
如果现有的KeyStore对象需要与基于Builder的API一起使用,这非常有用。
| Parameters | |
|---|---|
keyStore |
KeyStore: the KeyStore to be encapsulated |
protectionParameter |
KeyStore.ProtectionParameter: the ProtectionParameter used to protect the KeyStore entries |
| Returns | |
|---|---|
KeyStore.Builder |
a new Builder object |
| Throws | |
|---|---|
NullPointerException |
if keyStore or protectionParameters is null |
IllegalArgumentException |
if the keyStore has not been initialized |