APIdia Launch Partner
Top Description Inners Constructors Methods
javax.xml.crypto

public abstract Class KeySelector

extends Object
Class Inheritance
Known Direct Subclasses
javax.xml.crypto.KeySelector.SingletonKeySelector
Imports
java.security.Key, javax.xml.crypto.dsig.keyinfo.KeyInfo, .RetrievalMethod

A selector that finds and returns a key using the data contained in a KeyInfo object. An example of an implementation of this class is one that searches a java.security.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.

Authors
Sean Mullan, JSR 105 Expert Group
Since
1.6

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
KeySelector.Purpose

The purpose of the key that is to be selected.

private static class

Constructor Summary

AccessConstructor and Description
protected
KeySelector()

Default no-args constructor; intended for invocation by subclasses only.

Method Summary

Modifier and TypeMethod and Description
public abstract KeySelectorResult

Returns:

the result of the key selector
select
(KeyInfo
a KeyInfo (may be null)
keyInfo
,
KeySelector.Purpose purpose, AlgorithmMethod
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.
method
,
XMLCryptoContext
an XMLCryptoContext that may contain useful information for finding an appropriate key. If this key selector supports resolving RetrievalMethod types, the context's baseURI and dereferencer parameters (if specified) should be used by the selector to resolve and dereference the URI.
context
)

Attempts to find a key that satisfies the specified constraints.

public static KeySelector

Returns:

a key selector that always selects the specified key
singletonKeySelector
(Key
the sole key to be stored in the key selector
key
)

Returns a KeySelector that always selects the specified key, regardless of the KeyInfo passed to it.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

KeySelectorback to summary
protected KeySelector()

Default no-args constructor; intended for invocation by subclasses only.

Method Detail

selectback to summary
public abstract KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException

Attempts to find a key that satisfies the specified constraints.

Parameters
keyInfo:KeyInfo

a KeyInfo (may be null)

purpose:KeySelector.Purpose

the key's purpose (Purpose#SIGN, Purpose#VERIFY, Purpose#ENCRYPT, or Purpose#DECRYPT)

method:AlgorithmMethod

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:XMLCryptoContext

an XMLCryptoContext that may contain useful information for finding an appropriate key. If this key selector supports resolving RetrievalMethod types, the context's baseURI and dereferencer parameters (if specified) should be used by the selector to resolve and dereference the URI.

Returns:KeySelectorResult

the result of the key selector

Exceptions
KeySelectorException:
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:
if the data type of method is not supported by this key selector
singletonKeySelectorback to summary
public static KeySelector singletonKeySelector(Key key)

Returns a KeySelector that always selects the specified key, regardless of the KeyInfo passed to it.

Parameters
key:Key

the sole key to be stored in the key selector

Returns:KeySelector

a key selector that always selects the specified key

Exceptions
NullPointerException:
if key is null
javax.xml.crypto back to summary

public Class KeySelector.Purpose

extends Object
Class Inheritance

The purpose of the key that is to be selected.

Field Summary

Modifier and TypeField and Description
public static final KeySelector.Purpose
DECRYPT

A key for decrypting.

public static final KeySelector.Purpose
ENCRYPT

A key for encrypting.

private final String
public static final KeySelector.Purpose
SIGN

A key for signing.

public static final KeySelector.Purpose
VERIFY

A key for verifying.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

a string representation of this purpose
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this purpose ("sign", "verify", "encrypt", or "decrypt").

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

DECRYPTback to summary
public static final KeySelector.Purpose DECRYPT

A key for decrypting.

ENCRYPTback to summary
public static final KeySelector.Purpose ENCRYPT

A key for encrypting.

nameback to summary
private final String name
SIGNback to summary
public static final KeySelector.Purpose SIGN

A key for signing.

VERIFYback to summary
public static final KeySelector.Purpose VERIFY

A key for verifying.

Constructor Detail

Purposeback to summary
private Purpose(String name)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this purpose ("sign", "verify", "encrypt", or "decrypt").

Returns:String

a string representation of this purpose

javax.xml.crypto back to summary

private Class KeySelector.SingletonKeySelector

extends KeySelector
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Key

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public KeySelectorResult
select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context)

Implements abstract javax.xml.crypto.KeySelector.select.

Attempts to find a key that satisfies the specified constraints.

Inherited from javax.xml.crypto.KeySelector:
singletonKeySelector

Field Detail

keyback to summary
private final Key key

Constructor Detail

SingletonKeySelectorback to summary
pack-priv SingletonKeySelector(Key key)

Method Detail

selectback to summary
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException

Implements abstract javax.xml.crypto.KeySelector.select.

Doc from javax.xml.crypto.KeySelector.select.

Attempts to find a key that satisfies the specified constraints.

Exceptions
KeySelectorException:
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.