Hutool DES 加密出现IllegalBlockSizeException: input is too short!

最近帮公司写一个清除相关数据的小工具, 由于需要给不懂技术的同事使用,所有用hutool的DES对称加密 数据库的账号 密码,想不到用户名太短,出现IllegalBlockSizeException: input is too short!

难道加密个字符串还需要长度限制吗?感觉不太对。 去hutool项目的issue中找了找,发现有人提过这个问题,issue地址

Hutool DES 加密出现IllegalBlockSizeException: input is too short!

项目拥有者 是说 iv导致的块大小问题,那说明确实是个问题,而且说明是已经解决了的。图中出现问题的版本是4.6.1,查看自己的版本

Hutool DES 加密出现IllegalBlockSizeException: input is too short!

用的是5.2.3,不会是老版本解决了,新版本还不行吧? 不想改版本, 直接换个思路解决这个问题, 把需要加密的字符串 统一添加 固定的一串字符比如 个人或公司域名

Hutool DES 加密出现IllegalBlockSizeException: input is too short!

把加密出来的字符串写到配置文件中。
读取配置文件解密的时候,把固定字符替换成空白即可

Hutool DES 加密出现IllegalBlockSizeException: input is too short!