Example usage for javax.xml.crypto AlgorithmMethod getAlgorithm

List of usage examples for javax.xml.crypto AlgorithmMethod getAlgorithm

Introduction

In this page you can find the example usage for javax.xml.crypto AlgorithmMethod getAlgorithm.

Prototype

String getAlgorithm();

Source Link

Document

Returns the algorithm URI of this AlgorithmMethod.

Usage

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.DocumentFactory.java

public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method,
        XMLCryptoContext context) throws KeySelectorException {
    Iterator ki = keyInfo.getContent().iterator();
    while (ki.hasNext()) {
        XMLStructure info = (XMLStructure) ki.next();
        if (!(info instanceof X509Data))
            continue;
        X509Data x509Data = (X509Data) info;
        Iterator xi = x509Data.getContent().iterator();
        while (xi.hasNext()) {
            Object o = xi.next();
            if (!(o instanceof X509Certificate))
                continue;
            final PublicKey key = ((X509Certificate) o).getPublicKey();
            // Make sure the algorithm is compatible
            // with the method.
            if (algEquals(method.getAlgorithm(), key.getAlgorithm())) {
                return new KeySelectorResult() {
                    public Key getKey() {
                        return key;
                    }//from   w ww .  j  a  va 2 s  .  co  m
                };
            }
        }
    }
    Logger.getLogger(this.getClass()).error("No Key found");
    throw new KeySelectorException("No key found!");
}