java.lang.Object
javax.xml.crypto.KeySelector
一个选择器,使用包含在
KeyInfo 对象中的数据来查找并返回一个密钥。该类的一个实现示例是搜索一个 KeyStore,以匹配 KeyInfo 中包含的信息的受信任密钥。
返回的密钥是否受信任以及用于确定的机制是特定于实现的。
- 自版本:
- 1.6
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract KeySelectorResultselect(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) 尝试查找满足指定约束的密钥。static KeySelectorsingletonKeySelector(Key key) 返回一个KeySelector,始终选择指定的密钥,而不管传递给它的KeyInfo。
-
Constructor Details
-
KeySelector
protected KeySelector()默认无参构造函数;仅供子类调用。
-
-
Method Details
-
select
public abstract KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException 尝试查找满足指定约束的密钥。- 参数:
-
keyInfo- 一个KeyInfo(可能为null) -
purpose- 密钥的目的(KeySelector.Purpose.SIGN、KeySelector.Purpose.VERIFY、KeySelector.Purpose.ENCRYPT或KeySelector.Purpose.DECRYPT) -
method- 用于此密钥的算法方法。只有与算法兼容且符合指定算法约束的密钥应返回。 -
context- 可能包含有助于找到适当密钥的有用信息的XMLCryptoContext。如果此密钥选择器支持解析RetrievalMethod类型,则选择器应使用上下文的baseURI和dereferencer参数(如果指定)来解析和取消引用 URI。 - 返回:
- 密钥选择器的结果
- 抛出:
-
KeySelectorException- 尝试查找密钥时发生异常情况。请注意,无法找到密钥不被视为异常(在这种情况下应返回null)。但是,阻止KeySelector找到潜在密钥的错误条件(例如:网络通信故障)应被视为异常。 -
ClassCastException- 如果method的数据类型不受此密钥选择器支持
-
singletonKeySelector
返回一个KeySelector,始终选择指定的密钥,而不管传递给它的KeyInfo。- 参数:
-
key- 要存储在密钥选择器中的唯一密钥 - 返回:
- 始终选择指定密钥的密钥选择器
- 抛出:
-
NullPointerException- 如果key为null
-