I generated a public key in Java from a .PEM file as follows :
PublicKey pub = null;
KeyFactory factory = KeyFactory.getInstance("RSA", "BC");
try {
/*PrivateKey priv = generatePrivateKey(factory, RESOURCES_DIR
+ "id_rsa");*/
pub = generatePublicKey(factory, RESOURCES_DIR
+ "rsa_2048_pub.pem");
} catch (InvalidKeySpecException e) {
e.printStackTrace();
}
And then I converted it to string as follows :
String encodedPublicKey = Base64.getEncoder().encodeToString(pub.getEncoded());
Now how can I convert it from string to public key to have it as type of PublicKey again ?