简体   繁体   English

有弹性的城堡PKCS7填充

[英]Bouncy Castle PKCS7 padding

I need help to find what is actually a padding value for this expression in Bouncy Castle java framework. 我需要帮助来找到Bouncy Castle Java框架中此表达式的实际填充值。 Kinda not sure about the values. Kinda不确定这些值。

encrypt(bytes, iv, secret, "AES/CBC/PKCS7Padding")

The padding byte used is the same as the number of padding bytes. 使用的填充字节与填充字节的数量相同。 Thus, if 11 bytes of padding are needed then that padding consists of 11 copies of the byte 0x0b. 因此,如果需要填充11个字节,则该填充由字节0x0b的11个副本组成。 Padding is always applied, so that if the number of bytes is already a multiple of 16 then 16 bytes of padding are used, the pad byte being 0x10 in that case. 始终应用填充,因此,如果字节数已经是16的倍数,则使用16字节的填充,在这种情况下,填充字节为0x10。

This padding scheme has the nice feature that, upon decryption, you can examine the last byte of the padded plaintext to determine how many padding bytes there are in total. 这种填充方案具有很好的功能,即在解密后,您可以检查填充的纯文本的最后一个字节,以确定总共有多少个填充字节。

Note that PKCS7 padding is not a java-specific standard but rather a very common padding scheme independent of language. 请注意,PKCS7填充不是Java特定的标准,而是一种独立于语言的非常常见的填充方案。

If the original data is an integer multiple of N bytes, then an extra block of bytes with value N is added. 如果原始数据是N个字节的整数倍,那么将添加一个额外的字节块,其值为N。 This is necessary so the deciphering algorithm can determine with certainty whether the last byte of the last block is a pad byte indicating the number of padding bytes added or part of the plaintext message. 这是必需的,以便解密算法可以确定地确定最后一个块的最后一个字节是填充字节,该填充字节指示添加的填充字节数或明文消息的一部分。 Consider a plaintext message that is an integer multiple of N bytes with the last byte of plaintext being 01. With no additional information, the deciphering algorithm will not be able to determine whether the last byte is a plaintext byte or a pad byte. 考虑一个纯文本消息,该消息是N字节的整数倍,而纯文本的最后一个字节为01。如果没有其他信息,解密算法将无法确定最后一个字节是纯文本字节还是填充字节。 However, by adding N bytes each of value N after the 01 plaintext byte, the deciphering algorithm can always treat the last byte as a pad byte and strip the appropriate number of pad bytes off the end of the ciphertext; 但是,通过在01个明文字节之后添加N个字节,每个字节的值N,解密算法可以始终将最后一个字节视为填充字节,并从密文末尾剥离适当数量的填充字节; said number of bytes to be stripped based on the value of the last byte. 表示要基于最后一个字节的值剥离的字节数。

PKCS7填充

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM