码迷,mamicode.com
首页 > 其他好文 > 详细

两个实用的方法从Base64字符串生成RSAPublicKey及RSAPrivatekey

时间:2015-07-21 12:22:52      阅读:516      评论:0      收藏:0      [点我收藏+]

标签:

 1     public static RSAPublicKey getRSAPublidKeyBybase64(String base64s) {
 2         X509EncodedKeySpec keySpec = new X509EncodedKeySpec(CodeUtils.base64Decode(base64s));
 3         RSAPublicKey publicKey = null;
 4 
 5         try {
 6             publicKey = (RSAPublicKey)keyFactory.generatePublic(keySpec);
 7         } catch (InvalidKeySpecException var4) {
 8             LOGGER.error("base64编码=" + base64s + "转RSA公钥失败", var4);
 9         }
10 
11         return publicKey;
12     }
13 
14     public static RSAPrivateKey getRSAPrivateKeyBybase64(String base64s) {
15         PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(CodeUtils.base64Decode(base64s));
16         RSAPrivateKey privateKey = null;
17 
18         try {
19             privateKey = (RSAPrivateKey)keyFactory.generatePrivate(keySpec);
20         } catch (InvalidKeySpecException var4) {
21             LOGGER.error("base64编码=" + base64s + "转RSA私钥失败", var4);
22         }
23 
24         return privateKey;
25     }

 

两个实用的方法从Base64字符串生成RSAPublicKey及RSAPrivatekey

标签:

原文地址:http://www.cnblogs.com/frankyou/p/4663780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!