Here you can find the source of getPublicKey(String key)
public static PublicKey getPublicKey(String key) throws Exception
//package com.java2s; //License from project: Open Source License import sun.misc.BASE64Decoder; import java.security.*; import java.security.spec.X509EncodedKeySpec; public class Main { public static PublicKey getPublicKey(String key) throws Exception { byte[] keyBytes; keyBytes = (new BASE64Decoder()).decodeBuffer(key); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); return keyFactory.generatePublic(keySpec); }/*w w w. jav a 2 s . co m*/ }