由于未知的 KeySpec 类型,我无法使用 bouncycastle 生成私钥:java.security.spec.X509EncodedKeySpec。(但是对公钥做同样的事情不会抛出异常并且有效 - 为什么?)
java.security.spec.InvalidKeySpecException:未知 KeySpec 类型:java.security.spec.X509EncodedKeySpec 在 org.bouncycastle.jcajce.provider.asymmetric.rsa.KeyFactorySpi.engineGeneratePrivate(未知来源)在 java.security.KeyFactory.generatePrivate(KeyFactory.爪哇:366)
PemReader pemReader = new PemReader(new InputStreamReader(new FileInputStream("private_unencrypted.pem")));
PemObject pemObject = pemReader.readPemObject();
pemReader.close();
KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");
byte[] privateKeyBytes = pemObject.getContent();
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(privateKeyBytes);
PrivateKey privateKey = keyFactory.generatePrivate(x509KeySpec);
芜湖不芜
相关分类