Search in sources :

Example 6 with RSAKeyValue

use of org.apache.xml.security.keys.content.keyvalues.RSAKeyValue in project santuario-java by apache.

the class RSAKeyValueResolver method engineLookupAndResolvePublicKey.

/**
 * {@inheritDoc}
 */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage) {
    if (element == null) {
        return null;
    }
    LOG.debug("Can I resolve {}", element.getTagName());
    boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYVALUE);
    Element rsaKeyElement = null;
    if (isKeyValue) {
        rsaKeyElement = XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_RSAKEYVALUE, 0);
    } else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_RSAKEYVALUE)) {
        // this trick is needed to allow the RetrievalMethodResolver to eat a
        // ds:RSAKeyValue directly (without KeyValue)
        rsaKeyElement = element;
    }
    if (rsaKeyElement == null) {
        return null;
    }
    try {
        RSAKeyValue rsaKeyValue = new RSAKeyValue(rsaKeyElement, baseURI);
        return rsaKeyValue.getPublicKey();
    } catch (XMLSecurityException ex) {
        LOG.debug("XMLSecurityException", ex);
    }
    return null;
}
Also used : RSAKeyValue(org.apache.xml.security.keys.content.keyvalues.RSAKeyValue) Element(org.w3c.dom.Element) XMLSecurityException(org.apache.xml.security.exceptions.XMLSecurityException)

Aggregations

RSAKeyValue (org.apache.xml.security.keys.content.keyvalues.RSAKeyValue)6 DSAKeyValue (org.apache.xml.security.keys.content.keyvalues.DSAKeyValue)5 PublicKey (java.security.PublicKey)3 Element (org.w3c.dom.Element)3 BigInteger (java.math.BigInteger)2 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)2 X509Data (org.apache.xml.security.keys.content.X509Data)2 XMLSignatureException (com.sun.identity.saml.xmlsig.XMLSignatureException)1 TransformerException (javax.xml.transform.TransformerException)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1