我从.PEM文件生成Java中的公钥,如下所示:
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();
}
然后我将其转换为字符串,如下所示:
String encodedPublicKey = Base64.getEncoder().encodeToString(pub.getEncoded());
现在我如何将其从字符串转换为公钥,以便再次将其作为 PublicKey 的类型?