Here you can find the source of getPublicKeyFromKeyInfo(Node keyInfoNode)
public static PublicKey getPublicKeyFromKeyInfo(Node keyInfoNode) throws ParserConfigurationException, SAXException, IOException
//package com.java2s; /*//from w w w . j av a 2s . c o m * Copyright 2010 University of Chicago * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * NOTE: This is a _PROTOTYPE_ implementation and is not intended for * production use. * @src https://svn.cagrid.org/trunk/cagrid/restsecurity/cagrid-restsecurity-common/src/main/java/org/cagrid/security/rest/util/SecurityUtil.java */ import java.io.IOException; import java.math.BigInteger; import java.security.KeyFactory; import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.RSAPublicKeySpec; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import org.apache.commons.codec.binary.Base64; import org.w3c.dom.Node; import org.xml.sax.SAXException; public class Main { static XPathExpression keyModulusPath = null; static XPathExpression keyExponentPath = null; static KeyFactory rsaKeyFactory = null; public static PublicKey getPublicKeyFromKeyInfo(Node keyInfoNode) throws ParserConfigurationException, SAXException, IOException { PublicKey publicKey = null; try { String modulusString = keyModulusPath.evaluate(keyInfoNode); String exponentString = keyExponentPath.evaluate(keyInfoNode); if (modulusString == null || exponentString == null) { return null; } byte[] modulusBytes = Base64.decodeBase64(modulusString); BigInteger modulus = new BigInteger(1, modulusBytes); byte[] exponentBytes = Base64.decodeBase64(exponentString); BigInteger exponent = new BigInteger(1, exponentBytes); RSAPublicKeySpec keySpec = new RSAPublicKeySpec(modulus, exponent); publicKey = rsaKeyFactory.generatePublic(keySpec); } catch (XPathExpressionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidKeySpecException e) { e.printStackTrace(); } return publicKey; } }