加密Java aes解密bytebuffer,包括填充为空字节
我正在尝试将加密字节[]的加密代码迁移到bytebuffer,以便更好地与其他API集成
前面使用字节[8]的代码工作正常,其中解密的输出正好是未加密的字节[8]
但是,当迁移到bytebuffer时,解密的bytebuffer是一个bytebuffer,其大小不是原始消息的大小,而是原始消息+填充,即填充定义为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();
共 (0) 个答案