I am generating my keypair like this:
KeyPair kp = null;
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(2048);
kp = kpg.generateKeyPair();
and I get my public key like this:
PublicKey publicKey = kp.getPublic();
byte[] publicKeyBytes = publicKey.getEncoded();
String publicKeyEncoded = new String(Base64.encode(publicKeyBytes, Base64.DEFAULT));
What I get in return is perfectly fine key, but the server is accepting keys in the format in which I need to have starting and ending tags
-----BEGIN PUBLIC KEY-----
-----END PUBLIC KEY-----
Should I add these tags myself in the encoded key or there is some method/format in Java that gives me the key in the following format?