{
System.out.println("*******************");
if (Security.getProvider("BC") == null) Security.addProvider(new BouncyCastleProvider());
KeyPair keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
StringWriter writer = new StringWriter();
PEMWriter pemWriter = new PEMWriter(writer);
pemWriter.writeObject(keyPair.getPublic());
pemWriter.flush();
String s = writer.toString();
System.out.println(s);
s = PemUtils.removeBeginEnd(s);
PublicKey pk = PemUtils.decodePublicKey(s);