将RSAPublicKey转换为PEM

时间:2017-11-20 03:34:19

标签: java rsa public-key pem

我使用Java中的以下代码创建了RSAPublicKey和RSAPrivateKey。我想将此转换为PEM键,其中包含以----- BEGIN PUBLIC KEY -----开头的内容 ----- END PUBLIC KEY -----

 KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA");
 keyGenerator.initialize(2048);
 KeyPair keyPair = keyGenerator.genKeyPair();
 RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
 RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); 

我的publicKey看起来像这样

 Sun RSA public key, 2048 bits
 modulus: 24725677929965393399116311796579849208456694139830747885329642050536871708602127467509375984842143051004691282429145783432620678099378069556446495267888717074390817963266933346714989616542462975355537898417850941217923441420844383641690704416493960652901568109149478965331966323480000341094954977708922888113451561712134246092055663913101815995378690422053526513288907318201617969755234493423112606856093576711535203464948727407631244156513571088601573017696719030247683899442955936480784619914188425390154747719569488556784397642039320538767824471814998647925121013750739910552195629468326354683709340318053920864663
 public exponent: 65537

0 个答案:

没有答案