Java AES解密字节缓冲区,包括填充为空字节

问题描述

我正在尝试将对byte []进行加密的加密代码迁移到字节缓冲区,以便更好地与其他api集成。

先前使用byte [8]的代码可以正常工作,其中解密的输出正是未加密的byte [8]。

但是,当迁移到字节缓冲区时,解密后的字节缓冲区不是原始消息大小的字节缓冲区,而是原始消息+填充,即由padding定义为null的空间。

是否有一种使解密结果与输入相同的好方法

代码使用转换 AES / CBC / PKCS5Padding

//this gives the maximum size,including the possible padding,not the real size
int outputSize = cipher.getoutputSize(input.remaining());

ByteBuffer output = ByteBuffer.allocate(outputSize);

cipher.doFinal(input,output);

return output.rewind().asReadOnlyBuffer();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)