shuzheng/zheng · error · RuntimeException
兄弟,配置文件中的密码需要使用AES加密,请使用com.zheng.common.util.AESUtil工具类修改这些
Error message
兄弟,配置文件中的密码需要使用AES加密,请使用com.zheng.common.util.AESUtil工具类修改这些值!
What it means
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.
Source
Thrown at zheng-common/src/main/java/com/zheng/common/util/AESUtil.java:121
cipher.init(Cipher.DECRYPT_MODE, key);
//8.将加密并编码后的内容解码成字节数组
byte[] byteContent = new BASE64Decoder().decodeBuffer(content);
/*
* 解密
*/
byte[] byteDecode = cipher.doFinal(byteContent);
String aesDecode = new String(byteDecode, "utf-8");
return aesDecode;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
throw new RuntimeException("兄弟,配置文件中的密码需要使用AES加密,请使用com.zheng.common.util.AESUtil工具类修改这些值!");
//e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
//如果有错就返加nulll
return null;
}
public static void main(String[] args) {
String[] keys = {
"", "123456"
};
System.out.println("key | AESEncode | AESDecode");
for (String key : keys) {
System.out.print(key + " | ");
String encryptString = aesEncode(key);
System.out.print(encryptString + " | ");
String decryptString = aesDecode(encryptString);View on GitHub (pinned to 7005c0a775)
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.
Example fix
// before (application.properties)
jdbc.password=123456
// after
jdbc.password=<output of AESUtil.aesEncode("123456")> Defensive patterns
Strategy: validation
Validate before calling
String enc = props.getProperty("jdbc.password");
if (enc == null || enc.length() % 16 != 0) {
throw new IllegalStateException("jdbc.password is not AES-encrypted; run AESUtil.aesEncode first");
} Type guard
boolean isLikelyAesCiphertext(String v) {
return v != null && !v.isEmpty() && v.length() % 16 == 0;
} Try / catch
try {
String plain = AESUtil.decryptString(cfgValue);
if (plain == null) throw new IllegalStateException("AES decrypt failed for config value");
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("AES")) {
// value not encrypted with AESUtil; fix config
} else throw e;
} Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
AI-assisted analysis of shuzheng/zheng@7005c0a775 (2026-09-04).
Data as JSON: /api/errors/c854f46a900495e3.
Report an issue: GitHub.