首页 > 编程语言 > 详细

java生成RSA公私钥字符串,简单易懂

时间:2018-12-28 15:49:56      阅读:323      评论:0      收藏:0      [点我收藏+]

java生成RSA公私钥字符串,简单易懂

 

解决方法:

1.下载bcprov-jdk16-140.jar包,参考:http://www.yayihouse.com/yayishuwu/chapter/1537

2.java代码

KeyPairGenerator keyPairGenerator = KeyPairGenerator

                   .getInstance("RSA");

           keyPairGenerator.initialize(2048);

           KeyPair keyPair = keyPairGenerator.generateKeyPair();

           RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();

           RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();

           System.out.println("公钥:"+new BASE64Encoder().encodeBuffer(publicKey.getEncoded()));

           System.out.println("私钥:"+new BASE64Encoder().encodeBuffer(privateKey.getEncoded()));

 

java生成RSA公私钥字符串,简单易懂

原文:https://www.cnblogs.com/chinaifae/p/10190925.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!