{"record":{"id":"deddd11393c91921","repo":"binarywang/WxJava","slug":"error-deddd1","errorCode":null,"errorMessage":"请配置会话存档解密方式","messagePattern":"请配置会话存档解密方式","errorType":"exception","errorClass":"WxErrorException","httpStatus":null,"severity":"error","filePath":"weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/crypto/WxCpCryptUtil.java","lineNumber":55,"sourceCode":"    String corpId = wxCpConfigStorage.getCorpId();\n\n    this.token = token;\n    this.appidOrCorpid = corpId;\n    this.aesKey = Base64.getDecoder().decode(StringUtils.remove(encodingAesKey, \" \"));\n  }\n\n  /**\n   * 判断使用PKCS8或者PKCS1进行解密\n   *\n   * @param encryptRandomKey 使用PUBLICKEY_VER指定版本的公钥进行非对称加密后base64加密的内容\n   * @param msgAuditPriKey   会话存档私钥\n   * @param pkcs1            使用什么方式进行解密，1代表使用PKCS1进行解密，2代表PKCS8进行解密 ...\n   * @return string\n   * @throws Exception the exception\n   */\n  public static String decryptPriKey(String encryptRandomKey, String msgAuditPriKey, Integer pkcs1) throws Exception {\n    if (Objects.isNull(pkcs1)) {\n      throw new WxErrorException(\"请配置会话存档解密方式\");\n    }\n\n    if (Objects.equals(pkcs1, 1)) {\n      return decryptPriKeyByPKCS1(encryptRandomKey, msgAuditPriKey);\n    }\n\n    return decryptPriKeyByPKCS8(encryptRandomKey, msgAuditPriKey);\n  }\n\n  /**\n   * PKCS8 解密私钥\n   *\n   * @param encryptRandomKey the encrypt random key\n   * @param msgAuditPriKey   the msg audit pri key\n   * @return string\n   * @throws Exception the exception\n   */\n  public static String decryptPriKeyByPKCS8(String encryptRandomKey, String msgAuditPriKey) throws Exception {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/crypto/WxCpCryptUtil.java#L37-L73","documentation":"Thrown as WxErrorException when the pkcs1 parameter (decryption method selector) is null in WxCpCryptUtil.decryptPriKey(). This parameter must be 1 (PKCS1) or 2 (PKCS8) to select the RSA decryption mode for chat session archive (会话存档). A null value means the decryption mode was never configured.","triggerScenarios":"Calling WxCpCryptUtil.decryptPriKey(encryptRandomKey, msgAuditPriKey, null) without specifying the decryption method.","commonSituations":"Chat archive feature newly enabled without completing decryption config; version upgrade where the pkcs1 parameter was added but existing caller code was not updated; missing msgAuditDecryptMode setting in application configuration.","solutions":["Pass pkcs1 = 1 for PKCS1 keys or pkcs1 = 2 for PKCS8 keys","Configure the chat archive decryption mode in your application config and pass it through to decryptPriKey","Verify that the pkcs1 value is sourced from a non-null configuration property"],"exampleFix":"// before\nString key = WxCpCryptUtil.decryptPriKey(encryptRandomKey, priKey, null);\n\n// after\nString key = WxCpCryptUtil.decryptPriKey(encryptRandomKey, priKey, 2); // PKCS8","handlingStrategy":"validation","validationCode":"// Validate pkcs1 before calling decryptPriKey\nif (pkcs1 == null || (pkcs1 != 1 && pkcs1 != 2)) {\n  throw new IllegalArgumentException(\"pkcs1 must be 1 (PKCS1) or 2 (PKCS8)\");\n}\nWxCpCryptUtil.decryptPriKey(encryptRandomKey, msgAuditPriKey, pkcs1);","typeGuard":"private static boolean isValidPkcsMode(Integer pkcs1) {\n  return pkcs1 != null && (pkcs1 == 1 || pkcs1 == 2);\n}","tryCatchPattern":"try {\n  WxCpCryptUtil.decryptPriKey(encryptRandomKey, msgAuditPriKey, pkcs1);\n} catch (WxErrorException e) {\n  if (e.getMessage().contains(\"解密方式\")) {\n    log.error(\"Chat archive decryption mode not configured; set pkcs1 to 1 or 2\");\n  }\n  throw e;\n}","preventionTips":["Always set the chat archive decryption mode (pkcs1) in application configuration","Validate configuration completeness before enabling the chat archive feature","After library upgrades, check for new required configuration parameters"],"tags":["configuration","weixin-cp","crypto","chat-archive"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}