cipher.setAutoPadding([autoPadding])


  • autoPadding <boolean> 默认值: true
  • 返回值: <Cipher> 返回相同的 Cipher 实例,以便方法链调用。

在使用分组加密算法时,Cipher 类会自动将输入数据填充到适当的块大小。要禁用默认填充,请调用 cipher.setAutoPadding(false)

【When using block encryption algorithms, the Cipher class will automatically add padding to the input data to the appropriate block size. To disable the default padding call cipher.setAutoPadding(false).】

autoPaddingfalse 时,整个输入数据的长度必须是加密算法块大小的倍数,否则 cipher.final() 会抛出错误。禁用自动填充对于非标准填充非常有用,例如使用 0x0 替代 PKCS 填充。

【When autoPadding is false, the length of the entire input data must be a multiple of the cipher's block size or cipher.final() will throw an error. Disabling automatic padding is useful for non-standard padding, for instance using 0x0 instead of PKCS padding.】

cipher.setAutoPadding() 方法必须在 cipher.final() 之前调用。

【The cipher.setAutoPadding() method must be called before cipher.final().】