FileDocCategorySizeDatePackage
KeySelector.javaAPI DocJava SE 6 API4547Tue Jun 10 00:27:06 BST 2008javax.xml.crypto

KeySelector

public abstract class KeySelector extends Object
A selector that finds and returns a key using the data contained in a {@link KeyInfo} object. An example of an implementation of this class is one that searchs a {@link 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.

author
Sean Mullan
author
JSR 105 Expert Group
since
1.6

Fields Summary
Constructors Summary
protected KeySelector()
Default no-args constructor; intended for invocation by subclasses only.

    

                  
      
Methods Summary
public abstract javax.xml.crypto.KeySelectorResultselect(javax.xml.crypto.dsig.keyinfo.KeyInfo keyInfo, javax.xml.crypto.KeySelector$Purpose purpose, javax.xml.crypto.AlgorithmMethod method, javax.xml.crypto.XMLCryptoContext context)
Attempts to find a key that satisfies the specified constraints.

param
keyInfo a KeyInfo (may be null)
param
purpose the key's purpose ({@link Purpose#SIGN}, {@link Purpose#VERIFY}, {@link Purpose#ENCRYPT}, or {@link Purpose#DECRYPT})
param
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.
param
context an XMLCryptoContext that may contain useful information for finding an appropriate key. If this key selector supports resolving {@link RetrievalMethod} types, the context's baseURI and dereferencer parameters (if specified) should be used by the selector to resolve and dereference the URI.
return
the result of the key selector
throws
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.
throws
ClassCastException if the data type of method is not supported by this key selector

public static javax.xml.crypto.KeySelectorsingletonKeySelector(java.security.Key key)
Returns a KeySelector that always selects the specified key, regardless of the KeyInfo passed to it.

param
key the sole key to be stored in the key selector
return
a key selector that always selects the specified key
throws
NullPointerException if key is null

        return new SingletonKeySelector(key);