Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【企业微信】修复 sun.security.util 在高版本 java 中无法访问的问题,改为通过 bouncycastle 库解析私钥 #3216

Merged
merged 1 commit into from
Jan 12, 2024

Conversation

Demonese
Copy link

注意:该解决方法会额外为 cp 模块引入新的依赖库,如果有更好的写法欢迎提出。
相关 issue:#3211

@binarywang binarywang merged commit 5fad646 into binarywang:develop Jan 12, 2024
@binarywang binarywang added this to the 4.6.1 milestone Mar 2, 2024
borisbao pushed a commit to borisbao/WxJava that referenced this pull request Mar 23, 2024
@7757
Copy link

7757 commented Jun 6, 2024

目前版本是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); }

@7757
Copy link

7757 commented Jun 6, 2024

目前版本是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 之前用的是4.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

使用jdk21的时候,企业微信会话存档解密报错IllegalAccessError
3 participants