我有一个类似于以下内容的RSA公钥文件:
-----BEGIN RSA PUBLIC KEY-----
this is content
-----END RSA PUBLIC KEY-----
我使用Java来读取它:
KeyFactory factory = KeyFactory.getInstance("RSA");
KeySpec spec = new X509EncodedKeySpec(bytesFromThisFile); // bytesFromThisFile is created and filled correctly
PublicKey publicKey = factory.generatePublic(spec);
然后我遇到了一个异常:
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: invalid key format
如何正确读取文件?有没有办法将这个rsa公钥文件转换为Java可读格式?