cipher = XMLCipher.getInstance();
key = cipher.loadEncryptedKey(element);
}
catch (XMLSecurityException e)
{
throw new WSSecurityException("Could not parse encrypted key: " + e.getMessage(), e);
}
KeyInfo info = key.getKeyInfo();
if (info == null)
throw new WSSecurityException("EncryptedKey element did not contain KeyInfo");
PrivateKey privateKey = resolver.resolvePrivateKey(info);
// Locate the reference list. We have to manually parse this because xml security doesn't handle
// shorthand xpointer references (URI="#fooid")
Element referenceList = Util.findElement(element, Constants.XENC_REFERENCELIST, Constants.XML_ENCRYPTION_NS);
if (referenceList == null)
throw new WSSecurityException("Encrypted key did not contain a reference list");
this.list = new ReferenceList(referenceList);
// Now use the element list to determine the encryption alg
String alg = getKeyAlgorithm(element);
if (alg == null)
throw new WSSecurityException("Could not determine encrypted key algorithm!");
try
{
cipher.init(XMLCipher.UNWRAP_MODE, privateKey);
this.secretKey = (SecretKey) cipher.decryptKey(key, alg);
}
catch (XMLSecurityException e)
{
throw new WSSecurityException("Could not parse encrypted key: " + e.getMessage(), e);
}
this.document = element.getOwnerDocument();
this.token = new X509Token(resolver.resolveCertificate(info), this.document);
}