- java.lang.Object
-
- java.security.cert.CertStore
-
public class CertStore extends Object
从存储库检索Certificates和CRLs的类。这个类使用基于提供者的架构。 要创建一个
CertStore,请调用静态的getInstance方法之一,传递所需的类型为CertStore,任何适用的初始化参数和可选的所需提供商的名称。一旦
CertStore被创建,它可以被用来获取CertificateS和CRL通过调用以SgetCertificates种getCRLs方法。与提供对私钥和受信任证书的缓存的访问的
KeyStore不同,CertStore旨在提供对潜在的广泛的不受信任证书和CRL存储库的访问。 例如,CertStore的LDAP实现使用LDAP协议和RFC服务属性中定义的模式提供对存储在一个或多个目录中的证书和CRL的访问。Java平台的每个实现都需要支持以下标准
CertStore类型:-
Collection
并发访问
CertStore对象的所有公共方法必须是线程安全的。 也就是说,多个线程可以在单个CertStore对象(或多个)上同时调用这些方法,而不会产生不良影响。 例如,这允许CertPathBuilder搜索CRL,同时搜索其他证书。该类的静态方法也保证线程安全。 多个线程可以同时调用此类中定义的静态方法,而不会产生不良影响。
- 从以下版本开始:
- 1.4
-
-
-
构造方法摘要
构造方法 Modifier Constructor 描述 protectedCertStore(CertStoreSpi storeSpi, Provider provider, String type, CertStoreParameters params)创建给定类型的CertStore对象,并将给定的提供者实现(SPI对象)封装在其中。
-
方法摘要
所有方法 静态方法 接口方法 具体的方法 Modifier and Type 方法 描述 Collection<? extends Certificate>getCertificates(CertSelector selector)返回匹配指定选择器的Collection的Certificate。CertStoreParametersgetCertStoreParameters()返回用于初始化CertStore的参数。Collection<? extends CRL>getCRLs(CRLSelector selector)返回匹配指定选择器的Collection的CRL。static StringgetDefaultType()返回certstore.type安全属性指定的默认CertStore类型,如果不存在此属性,则返回字符串“LDAP”。static CertStoregetInstance(String type, CertStoreParameters params)返回实现指定的CertStore类型的CertStore对象,并使用指定的参数进行初始化。static CertStoregetInstance(String type, CertStoreParameters params, String provider)返回实现指定的CertStore类型的CertStore对象。static CertStoregetInstance(String type, CertStoreParameters params, Provider provider)返回实现指定的CertStore类型的CertStore对象。ProvidergetProvider()返回此CertStore的提供者。StringgetType()返回此CertStore的类型。
-
-
-
构造方法详细信息
-
CertStore
protected CertStore(CertStoreSpi storeSpi, Provider provider, String type, CertStoreParameters params)
创建给定类型的CertStore对象,并将给定的提供程序实现(SPI对象)封装在其中。- 参数
-
storeSpi- 提供者实现 -
provider- 提供商 -
type- 类型 -
params- 初始化参数(可能是null)
-
-
方法详细信息
-
getCertificates
public final Collection<? extends Certificate> getCertificates(CertSelector selector) throws CertStoreException
返回匹配指定选择器的Collection的Certificate。 如果Certificate与选择器匹配,则将返回一个空的Collection。对于一些
CertStore类型,结果Collection可能不包含与选择器匹配的所有Certificate。 例如,LDAPCertStore可能不会搜索目录中的所有条目。 相反,它可能只是搜索可能包含它正在寻找的Certificate的条目。一些
CertStore实现(特别是LDAPCertStore)可能会抛出一个CertStoreException除非提供了一个包含可用于查找证书的特定标准的非空CertSelector。 发行人和/或主题名称是特别有用的标准。- 参数
-
selector- ACertSelector用于选择应该返回哪些Certificate。 指定null返回所有Certificates(如果支持)。 - 结果
-
A
Collection的Certificates匹配指定的选择器(从不null) - 异常
-
CertStoreException- 如果发生异常
-
getCRLs
public final Collection<? extends CRL> getCRLs(CRLSelector selector) throws CertStoreException
返回匹配指定选择器的Collection的CRL。 如果没有CRL匹配选择器,将返回一个空的Collection。对于一些
CertStore类型,结果Collection可能不包含与选择器匹配的所有CRL。 例如,LDAPCertStore可能不搜索目录中的所有条目。 相反,它可能只是搜索可能包含它正在寻找的CRL的条目。一些
CertStore实现(特别是LDAPCertStore)可能会抛出一个CertStoreException除非提供了一个包含可用于查找CRL的特定标准的非空CRLSelector。 发行人名称和/或要检查的证书特别有用。- 参数
-
selector- ACRLSelector用于选择应该返回哪些CRL。 指定null以返回所有CRLs(如果支持)。 - 结果
-
A
Collection的CRLs匹配指定的选择器(从不null) - 异常
-
CertStoreException- 如果发生异常
-
getInstance
public static CertStore getInstance(String type, CertStoreParameters params) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException
返回实现指定的CertStore类型的CertStore对象,并使用指定的参数进行初始化。此方法遍历已注册的安全提供程序列表,从最优选的提供程序开始。 返回从支持指定类型的第一个Provider中封装CertStoreSpi实现的新CertStore对象。
注意,可以通过
Security.getProviders()方法检索已注册提供商的列表。返回的
CertStore将使用指定的CertStoreParameters初始化。 所需参数的类型可能因不同类型的CertStores而异。 请注意,指定的CertStoreParameters对象被克隆。- Implementation Note:
-
JDK参考实现另外使用
jdk.security.provider.preferredSecurity属性来确定指定算法的首选提供者顺序。 这可能与Security.getProviders()返回的提供商的顺序不同。 - 参数
-
type- 请求的名称CertStore类型。 有关标准类型的信息,请参阅Java Security Standard Algorithm Names Specification中的CertStore部分。 -
params- 初始化参数(可以是null)。 - 结果
-
一个实现指定的
CertStore类型的CertStore对象 - 异常
-
InvalidAlgorithmParameterException- 如果指定的初始化参数不适用于此CertStore -
NoSuchAlgorithmException- 如果否Provider支持指定类型的CertStoreSpi实现 -
NullPointerException- 如果type是null - 另请参见:
-
Provider
-
getInstance
public static CertStore getInstance(String type, CertStoreParameters params, String provider) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException
返回实现指定的CertStore类型的CertStore对象。返回从指定提供程序封装CertStoreSpi实现的新CertStore对象。 指定的提供者必须在安全提供程序列表中注册。
请注意,可以通过
Security.getProviders()方法检索注册提供商的列表。返回的
CertStore将使用指定的CertStoreParameters初始化。 所需参数的类型可能因不同类型的CertStore而异。 请注意,指定的CertStoreParameters对象被克隆。- 参数
-
type- 请求的CertStore类型。 有关标准类型的信息,请参阅Java Security Standard Algorithm Names Specification中的CertStore部分。 -
params- 初始化参数(可能为null)。 -
provider- 提供商的名称。 - 结果
-
一个
CertStore实现指定类型的对象 - 异常
-
IllegalArgumentException- 如果provider是null或空 -
InvalidAlgorithmParameterException- 如果指定的初始化参数不适用于此CertStore -
NoSuchAlgorithmException- 如果指定类型的CertStoreSpi实现不能从指定的提供者 -
NoSuchProviderException- 如果指定的提供程序未在安全提供程序列表中注册 -
NullPointerException- 如果type是null - 另请参见:
-
Provider
-
getInstance
public static CertStore getInstance(String type, CertStoreParameters params, Provider provider) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
返回实现指定的CertStore类型的CertStore对象。返回从指定的Provider对象封装CertStoreSpi实现的新CertStore对象。 请注意,指定的Provider对象不必在提供者列表中注册。
返回的
CertStore将使用指定的CertStoreParameters初始化。 所需参数的类型可能因不同类型的CertStore而异。 请注意,指定的CertStoreParameters对象被克隆。- 参数
-
type- 请求的CertStore类型。 有关标准类型的信息,请参阅Java Security Standard Algorithm Names Specification中的CertStore部分。 -
params- 初始化参数(可能是null)。 -
provider- 提供商。 - 结果
-
一个实现指定类型的
CertStore对象 - 异常
-
IllegalArgumentException- 如果provider为空 -
InvalidAlgorithmParameterException- 如果指定的初始化参数不适用于此CertStore -
NoSuchAlgorithmException- 如果指定类型的一个CertStoreSpi实现从指定的Provider对象不可用 -
NullPointerException- 如果type是null - 另请参见:
-
Provider
-
getCertStoreParameters
public final CertStoreParameters getCertStoreParameters()
返回用于初始化CertStore的参数。 请注意,CertStoreParameters对象在返回之前被克隆。- 结果
-
用于初始化这个
CertStore的参数(可能是null)
-
getType
public final String getType()
返回此CertStore的类型。- 结果
-
这种类型的
CertStore
-
getProvider
public final Provider getProvider()
返回此CertStore的提供者。- 结果
-
这个
CertStore的提供者
-
getDefaultType
public static final String getDefaultType()
返回由certstore.type安全属性指定的默认CertStore类型,如果没有此类属性,则返回字符串“LDAP”。默认的
CertStore类型可以由不想在使用getInstance方法时使用硬编码类型的应用程序使用,并且要提供默认的CertStore类型,以防用户未指定自己的。通过将
certstore.type安全属性的值设置为CertStore类型,可以更改默认值certstore.type类型。- 结果
-
由
certstore.type安全属性指定的默认CertStore类型,如果没有此类属性,则为字符串“LDAP”。 - 另请参见:
-
security properties
-
-