KeyPairGenerator kpg = KeyPairGenerator.getInstance(\"RSA\"); kpg.initialize(1024); KeyPair kp = kpg.genKeyPair(); Key publicKey = kp.getPublic(); Key privateKey = kp.ge
I use the following code to convert a PubliKey to PEM Base64 format
PubliKey
String publicKeyString = javax.xml.bind.DatatypeConverter.printBase64Binary(publicKey.getEncoded());
I hope it helps.