| | |
| | | /** 算法/模式/填充 */ |
| | | private static final String ALGORITHM = "AES/CBC/PKCS5Padding"; |
| | | |
| | | /** 默认 Key(HEX,32字节→256位密钥) */ |
| | | /** 默认 Key(HEX,16字节→128位密钥) */ |
| | | private static final String DEFAULT_KEY = "0F471C56362408AF8DB929C38EDFD23C"; |
| | | |
| | | /** 默认 IV(HEX,16字节→128位偏移量) */ |
| | |
| | | // ------------------------------------------------------------------------- |
| | | |
| | | /** |
| | | * HEX 字符串转字节数组(大小写均可) |
| | | * HEX 字符串转字节数组(大小写均可),不足 16 字节自动补 0 |
| | | */ |
| | | private static byte[] hexToBytes(String hex) { |
| | | if (hex == null || hex.length() % 2 != 0) { |
| | |
| | | data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) |
| | | + Character.digit(hex.charAt(i + 1), 16)); |
| | | } |
| | | // IV 不足 16 字节时补 0(兼容第三方 8 字节 IV) |
| | | if (data.length < 16) { |
| | | byte[] padded = new byte[16]; |
| | | System.arraycopy(data, 0, padded, 0, data.length); |
| | | data = padded; |
| | | } |
| | | return data; |
| | | } |
| | | |