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 }
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/15852.html