Here you can find the source of getPublicKey()
public static String getPublicKey()
//package com.java2s; //License from project: Open Source License import java.security.Key; import java.security.KeyFactory; import java.security.PublicKey; import java.security.spec.X509EncodedKeySpec; import java.util.HashMap; import sun.misc.BASE64Encoder; public class Main { public static String KEY_PAIRGENO = "RSA"; public static String PUBLIC_KEY = "PUBLIC_KEY"; public static HashMap<String, Object> keyMap; public static String getPublicKey() { Key key = (Key) keyMap.get(PUBLIC_KEY); byte[] bytes = key.getEncoded(); BASE64Encoder base64Encoder = new BASE64Encoder(); return base64Encoder.encode(bytes); }// ww w. j av a2s .co m public static PublicKey getPublicKey(byte[] keyBytes) throws Exception { X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance(KEY_PAIRGENO); PublicKey publicKey = keyFactory.generatePublic(keySpec); return publicKey; } }