| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…bouncycastle 库解析私钥
|
目前版本是4.6.0 为什么跟pr的不一致呢 public static String decryptPriKeyByPKCS1(String encryptRandomKey, String msgAuditPriKey) throws Exception { String privateKey = msgAuditPriKey.replaceAll("(\r\n|\r|\n|\n\r)", "").replace("-----BEGIN RSA PRIVATE KEY-----", "").replace("-----END RSA PRIVATE KEY-----", "").replace(" ", ""); byte[] keyBytes = Base64.getDecoder().decode(privateKey); DerValue[] seq = (new DerInputStream(keyBytes)).getSequence(0); RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(seq[1].getBigInteger(), seq[2].getBigInteger(), seq[3].getBigInteger(), seq[4].getBigInteger(), seq[5].getBigInteger(), seq[6].getBigInteger(), seq[7].getBigInteger(), seq[8].getBigInteger()); PrivateKey priKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec); Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(2, priKey); byte[] utf8 = cipher.doFinal(Base64.getDecoder().decode(encryptRandomKey)); return new String(utf8, StandardCharsets.UTF_8); } |
Sorry, something went wrong.
sorry 之前用的是4.6.0 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
注意:该解决方法会额外为 cp 模块引入新的依赖库,如果有更好的写法欢迎提出。
相关 issue:#3211