- 企业微信会话存档解密encryptRandomKey失败
解密代码如下: /** * 私钥解密 * * @param ciphertext 被加密字符串 * @return 解密后字符串 */ public static String decryptByPriKey(String ciphertext, String privateKeyStr) { log.info("私钥解密 ciphertext:【{}】,privateKeyStr:【{}】",ciphertext ,privateKeyStr); PrivateKey privateKey = null; try { Reader privateKeyReader = new StringReader(privateKeyStr); PEMParser privatePemParser = new PEMParser(privateKeyReader); Object privateObject = privatePemParser.readObject(); Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); if (privateObject instanceof PEMKeyPair) { PEMKeyPair pemKeyPair = (PEMKeyPair) privateObject; JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC"); privateKey = converter.getPrivateKey(pemKeyPair.getPrivateKeyInfo()); } Cipher rsa = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC"); rsa.init(Cipher.DECRYPT_MODE, privateKey); byte[] utf8 = rsa.doFinal(Base64.getDecoder().decode(ciphertext)); return new String(utf8, StandardCharsets.UTF_8); } catch (Exception e) { e.printStackTrace(); } return null; } 报错如下: org.bouncycastle.jcajce.provider.util.BadBlockException: unable to decrypt block at org.bouncycastle.jcajce.provider.asymmetric.rsa.CipherSpi.getOutput(Unknown Source) at org.bouncycastle.jcajce.provider.asymmetric.rsa.CipherSpi.engineDoFinal(Unknown Source) at javax.crypto.Cipher.doFinal(Cipher.java:2164) at com.qdum.workwechat.common.utils.vm.RSAUtils.decryptByPriKey(RSAUtils.java:87) at com.qdum.workwechat.common.utils.vm.WorkMsgBackUpUtil.main(WorkMsgBackUpUtil.java:282) Caused by: org.bouncycastle.crypto.InvalidCipherTextException: block incorrect at org.bouncycastle.crypto.encodings.PKCS1Encoding.decodeBlock(Unknown Source) at org.bouncycastle.crypto.encodings.PKCS1Encoding.processBlock(Unknown Source) ... 5 more 疑问,是什么原因会导致这个问题那,会话存档公钥配置错误?
2021-11-22 - 您好 问一下 普通商户开通H5支付提示 “当天商户号正在享受优惠费率,暂不支持开通” 怎么处理
[图片]怎么才能开通
2020-10-20