FileDocCategorySizeDatePackage
EncryptedKeyResolver.javaAPI DocJava SE 6 API4305Tue Jun 10 00:23:02 BST 2008com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations

EncryptedKeyResolver

public class EncryptedKeyResolver extends KeyResolverSpi
The EncryptedKeyResolver is not a generic resolver. It can only be for specific instantiations, as the key being unwrapped will always be of a particular type and will always have been wrapped by another key which needs to be recursively resolved. The EncryptedKeyResolver can therefore only be instantiated with an algorithm. It can also be instantiated with a key (the KEK) or will search the static KeyResolvers to find the appropriate key.
author
Berin Lautenbach

Fields Summary
static Logger
log
{@link java.util.logging} logging facility
Key
_key
Key
_kek
String
_algorithm
Constructors Summary
public EncryptedKeyResolver(String algorithm)
Constructor for use when a KEK needs to be derived from a KeyInfo list

param
algorithm


	                	 
	   
		_key = null;
		_kek = null;
        _algorithm=algorithm;
	
public EncryptedKeyResolver(String algorithm, Key kek)
Constructor used for when a KEK has been set

param
algorithm
param
kek

		_key = null;
		_algorithm = algorithm;
		_kek = kek;

	
Methods Summary
public booleanengineCanResolve(org.w3c.dom.Element element, java.lang.String BaseURI, com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver storage)
Method engineCanResolve

param
element
param
BaseURI
param
storage
return
true if can resolve the key in the element

	  if (true)
	  	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "EncryptedKeyResolver - Can I resolve " + element.getTagName());

      if (element == null) {
         return false;
      }

      boolean isEncryptedKey = XMLUtils.elementIsInEncryptionSpace(element,
                              EncryptionConstants._TAG_ENCRYPTEDKEY);

      if (isEncryptedKey) {
		  if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Passed an Encrypted Key");
		  try {
			  XMLCipher cipher = XMLCipher.getInstance();
			  cipher.init(XMLCipher.UNWRAP_MODE, _kek);
			  EncryptedKey ek = cipher.loadEncryptedKey(element);
			  _key = cipher.decryptKey(ek, _algorithm);
		  }
		  catch (Exception e) {}
      }
	  
      return (_key != null);
   
public java.security.PublicKeyengineResolvePublicKey(org.w3c.dom.Element element, java.lang.String BaseURI, com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver storage)

inheritDoc


	   return null;
   
public javax.crypto.SecretKeyengineResolveSecretKey(org.w3c.dom.Element element, java.lang.String BaseURI, com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver storage)

inheritDoc

      return (SecretKey) _key;
   
public java.security.cert.X509CertificateengineResolveX509Certificate(org.w3c.dom.Element element, java.lang.String BaseURI, com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver storage)

inheritDoc

      return null;