【问题标题】:java aes encryption , output has one block more than the input , and without paddingjava aes加密,输出比输入多一个块,并且没有填充
【发布时间】:2013-04-17 08:11:33
【问题描述】:

所以我正在处理这个任务,我应该使用预定义的 aes 函数制作我自己的 CBC 和 CTR 算法,现在我似乎有一个问题,输出的大小总是比输入多一个块(输入 64 ,输出 80 等等)这是我正在使用的代码,十六进制到字节转换和字节到十六进制:

public static String encrypt(String PT,String skey) throws Exception, NoSuchPaddingException {
      Cipher cipher = Cipher.getInstance("AES");
        SecretKeySpec key = new SecretKeySpec(skey.getBytes("ascii"), "AES");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        byte[] val = hexToBytes(PT);
        byte[] encVal = cipher.doFinal(val);

        return byteToString(encVal);
}

转换函数完美运行,val 大小为 n * 16 字节,encVal 大小为 (n+1) * 16 字节

【问题讨论】:

  • 您需要阅读文档。

标签: java size aes output


【解决方案1】:

这是由于填充。

Cipher.getInstance("AES");

为模式和填充使用特定于提供商的默认值。对于 JDK 6 和 7,这将默认为 AES/ECB/PKCS5Padding。

【讨论】:

猜你喜欢
  • 2022-12-14
  • 2013-09-25
  • 2018-03-25
  • 1970-01-01
  • 1970-01-01
  • 2021-12-12
  • 1970-01-01
  • 1970-01-01
  • 2011-10-16
相关资源
最近更新 更多