KeySelector (Java Platform SE 8 ) (original) (raw)
- javax.xml.crypto.KeySelector
public abstract class KeySelector
extends Object
A selector that finds and returns a key using the data contained in aKeyInfo object. An example of an implementation of this class is one that searches a KeyStore for trusted keys that match information contained in a KeyInfo
.
Whether or not the returned key is trusted and the mechanisms used to determine that is implementation-specific.
Since:
1.6
Nested Class Summary
Nested Classes
Modifier and Type Class Description static class KeySelector.Purpose The purpose of the key that is to be selected. Constructor Summary
Constructors
Modifier Constructor Description protected KeySelector() Default no-args constructor; intended for invocation by subclasses only. Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
Modifier and Type Method Description abstract KeySelectorResult select(KeyInfo keyInfo,KeySelector.Purpose purpose,AlgorithmMethod method,XMLCryptoContext context) Attempts to find a key that satisfies the specified constraints. static KeySelector singletonKeySelector(Key key) Returns a KeySelector that always selects the specified key, regardless of the KeyInfo passed to it. * ### Methods inherited from class java.lang.[Object](../../../java/lang/Object.html "class in java.lang") `[clone](../../../java/lang/Object.html#clone--), [equals](../../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../../java/lang/Object.html#finalize--), [getClass](../../../java/lang/Object.html#getClass--), [hashCode](../../../java/lang/Object.html#hashCode--), [notify](../../../java/lang/Object.html#notify--), [notifyAll](../../../java/lang/Object.html#notifyAll--), [toString](../../../java/lang/Object.html#toString--), [wait](../../../java/lang/Object.html#wait--), [wait](../../../java/lang/Object.html#wait-long-), [wait](../../../java/lang/Object.html#wait-long-int-)`
Constructor Detail
* #### KeySelector protected KeySelector() Default no-args constructor; intended for invocation by subclasses only.
Method Detail
* #### select public abstract [KeySelectorResult](../../../javax/xml/crypto/KeySelectorResult.html "interface in javax.xml.crypto") select([KeyInfo](../../../javax/xml/crypto/dsig/keyinfo/KeyInfo.html "interface in javax.xml.crypto.dsig.keyinfo") keyInfo, [KeySelector.Purpose](../../../javax/xml/crypto/KeySelector.Purpose.html "class in javax.xml.crypto") purpose, [AlgorithmMethod](../../../javax/xml/crypto/AlgorithmMethod.html "interface in javax.xml.crypto") method, [XMLCryptoContext](../../../javax/xml/crypto/XMLCryptoContext.html "interface in javax.xml.crypto") context) throws [KeySelectorException](../../../javax/xml/crypto/KeySelectorException.html "class in javax.xml.crypto") Attempts to find a key that satisfies the specified constraints. Parameters: `keyInfo` \- a `KeyInfo` (may be `null`) `purpose` \- the key's purpose ([KeySelector.Purpose.SIGN](../../../javax/xml/crypto/KeySelector.Purpose.html#SIGN),[KeySelector.Purpose.VERIFY](../../../javax/xml/crypto/KeySelector.Purpose.html#VERIFY), [KeySelector.Purpose.ENCRYPT](../../../javax/xml/crypto/KeySelector.Purpose.html#ENCRYPT), or[KeySelector.Purpose.DECRYPT](../../../javax/xml/crypto/KeySelector.Purpose.html#DECRYPT)) `method` \- the algorithm method that this key is to be used for. Only keys that are compatible with the algorithm and meet the constraints of the specified algorithm should be returned. `context` \- an `XMLCryptoContext` that may contain useful information for finding an appropriate key. If this key selector supports resolving [RetrievalMethod](../../../javax/xml/crypto/dsig/keyinfo/RetrievalMethod.html "interface in javax.xml.crypto.dsig.keyinfo") types, the context's `baseURI` and `dereferencer` parameters (if specified) should be used by the selector to resolve and dereference the URI. Returns: the result of the key selector Throws: `[KeySelectorException](../../../javax/xml/crypto/KeySelectorException.html "class in javax.xml.crypto")` \- if an exceptional condition occurs while attempting to find a key. Note that an inability to find a key is not considered an exception (`null` should be returned in that case). However, an error condition (ex: network communications failure) that prevented the `KeySelector` from finding a potential key should be considered an exception. `[ClassCastException](../../../java/lang/ClassCastException.html "class in java.lang")` \- if the data type of `method` is not supported by this key selector * #### singletonKeySelector public static [KeySelector](../../../javax/xml/crypto/KeySelector.html "class in javax.xml.crypto") singletonKeySelector([Key](../../../java/security/Key.html "interface in java.security") key) Returns a `KeySelector` that always selects the specified key, regardless of the `KeyInfo` passed to it. Parameters: `key` \- the sole key to be stored in the key selector Returns: a key selector that always selects the specified key Throws: `[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang")` \- if `key` is `null`
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.