Here you can find the source of getPublicKey(byte[] der)
private static PublicKey getPublicKey(byte[] der) throws NoSuchAlgorithmException, InvalidKeySpecException
//package com.java2s; //License from project: Open Source License import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; import java.security.interfaces.RSAPublicKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.X509EncodedKeySpec; public class Main { private static PublicKey getPublicKey(byte[] der) throws NoSuchAlgorithmException, InvalidKeySpecException { KeyFactory keyFactory = KeyFactory.getInstance("RSA"); // decode public key X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(der); RSAPublicKey pubKey = (RSAPublicKey) keyFactory .generatePublic(pubSpec); return pubKey; }// w ww.j a v a2 s . co m }