{"record":{"id":"c854f46a900495e3","repo":"shuzheng/zheng","slug":"aes-com-zheng-common-util-aesu","errorCode":null,"errorMessage":"兄弟，配置文件中的密码需要使用AES加密，请使用com.zheng.common.util.AESUtil工具类修改这些值！","messagePattern":"兄弟，配置文件中的密码需要使用AES加密，请使用com\\.zheng\\.common\\.util\\.AESUtil工具类修改这些值！","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"zheng-common/src/main/java/com/zheng/common/util/AESUtil.java","lineNumber":121,"sourceCode":"            cipher.init(Cipher.DECRYPT_MODE, key);\n            //8.将加密并编码后的内容解码成字节数组\n            byte[] byteContent = new BASE64Decoder().decodeBuffer(content);\n            /*\n             * 解密\n             */\n            byte[] byteDecode = cipher.doFinal(byteContent);\n            String aesDecode = new String(byteDecode, \"utf-8\");\n            return aesDecode;\n        } catch (NoSuchAlgorithmException e) {\n            e.printStackTrace();\n        } catch (NoSuchPaddingException e) {\n            e.printStackTrace();\n        } catch (InvalidKeyException e) {\n            e.printStackTrace();\n        } catch (IOException e) {\n            e.printStackTrace();\n        } catch (IllegalBlockSizeException e) {\n            throw new RuntimeException(\"兄弟，配置文件中的密码需要使用AES加密，请使用com.zheng.common.util.AESUtil工具类修改这些值！\");\n            //e.printStackTrace();\n        } catch (BadPaddingException e) {\n            e.printStackTrace();\n        }\n        //如果有错就返加nulll\n        return null;\n    }\n\n    public static void main(String[] args) {\n        String[] keys = {\n                \"\", \"123456\"\n        };\n        System.out.println(\"key | AESEncode | AESDecode\");\n        for (String key : keys) {\n            System.out.print(key + \" | \");\n            String encryptString = aesEncode(key);\n            System.out.print(encryptString + \" | \");\n            String decryptString = aesDecode(encryptString);","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/shuzheng/zheng/blob/7005c0a775e6d014d1dc8a8a809f7b1c13bf785a/zheng-common/src/main/java/com/zheng/common/util/AESUtil.java#L103-L139","documentation":"AESUtil.aesDecode throws this RuntimeException when AES decryption of a configuration value fails with IllegalBlockSizeException, which happens when the input string is not valid AES ciphertext produced by AESUtil.aesEncode. The library throws it deliberately with this message to tell the operator that plaintext passwords in the config file must first be encrypted with com.zheng.common.util.AESUtil. Note that on any other failure the method returns null instead of throwing.","triggerScenarios":"Calling decryptString/aesDecode on a property value that is plaintext (or otherwise not valid AES ciphertext with the expected block size), e.g. a raw password like 'password123' instead of the AES-encoded string.","commonSituations":"Developer checks in application.properties/jdbc.properties with plain-text DB or Redis passwords; a config value is partially copied/truncated so its length is not a multiple of the AES block size; values were encrypted with a different key or different cipher settings than the runtime AESUtil expects.","solutions":["Take the plaintext password, encrypt it with AESUtil.aesEncode (e.g. via its main method or a small utility run), and paste the encoded value into the config file.","Verify the encrypted string was not truncated, wrapped with extra whitespace/newlines, or re-encoded (URL/base64) by properties loading; escape or fix as needed.","Ensure the AES key used at decrypt time is identical to the one used to encrypt the values; re-encrypt with the runtime key if not.","If a value is intentionally not encrypted, remove it from the decrypt path instead of passing it to aesDecode."],"exampleFix":"// before (application.properties)\njdbc.password=123456\n// after\njdbc.password=<output of AESUtil.aesEncode(\"123456\")>","handlingStrategy":"validation","validationCode":"String enc = props.getProperty(\"jdbc.password\");\nif (enc == null || enc.length() % 16 != 0) {\n    throw new IllegalStateException(\"jdbc.password is not AES-encrypted; run AESUtil.aesEncode first\");\n}","typeGuard":"boolean isLikelyAesCiphertext(String v) {\n    return v != null && !v.isEmpty() && v.length() % 16 == 0;\n}","tryCatchPattern":"try {\n    String plain = AESUtil.decryptString(cfgValue);\n    if (plain == null) throw new IllegalStateException(\"AES decrypt failed for config value\");\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"AES\")) {\n        // value not encrypted with AESUtil; fix config\n    } else throw e;\n}","preventionTips":["Never commit plaintext passwords; encrypt every secret with AESUtil.aesEncode before adding it to config files.","Add a startup validator that decodes all encrypted properties and fails fast with a clear message.","Keep the AES key consistent across environments that share config files.","Watch for properties loaders mangling encoded values (backslashes, whitespace, encoding)."],"tags":["config","encryption","aes","runtime"],"backgroundTag":"plaintext-config-password-needs-encryption","analyzedSha":"7005c0a775e6d014d1dc8a8a809f7b1c13bf785a","analyzedAt":"2026-09-04T16:58:32.852Z","contentChangedAt":"2026-09-04T16:58:32.852Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}