使用块加密时填充包
PyPadding的Python项目详细描述
#pypadding
[![构建状态](https://travis-ci.org/blinglnav/pypadding.svg?(https://travis ci.org/blinglnav/pypadding)
>该包实现了使用块密码函数的填充方法。
*例如,当块大小为8时,b'hello'需要3个字节对于块大小的倍数-->;使用“b”\x03`(`b'hello\x03\x03\x03`)
``python
>;>pypadding import pkcs
>;>encoder=pkcs.encoder()
>;>encoder.encode(b'hello')
b'hello\x03\x03'
>;>编码器。解码(b'hello\x03\x03\x03')
b'hello'
````
```ansi x923
*pypadding.x923
*使用零填充(`b'\x00'`),最后一个字节设置为填充长度
*例如,当块大小为8时,b'hello'需要3个字节到块大小的倍数-->;使用“b”\x00'填充,最后一个字节设置为“b”\x03'`(`b'hello\x00\x00\x03'`)
``` python
>;>>;从pypadding导入x923
>;>encoder=x923.encoder()
>;>encoder.encode(b'hello')
b'hello\x00\x03'
>;>编码器。解码(b'hello\x00\x00\x03')
b'hello'
`````
iso 10126
*pypadding.iso10126
*使用随机字节填充,最后一个字节设置为padding长度
*例如,当块大小为8时,b'hello'需要3个字节到块大小的倍数-->;将随机字节和最后字节填充为“B'\x03'`(`B'Hello\x85\x85\xaa\x03'`B'Hello\x85\xaa\xx03'`)
>`python
>;从PyPadding导入iso10126
>;>gt;encoder=iso10126.encoder()
>;编码器。encode(B'Hello')
B'Hello\x85\xaa\x03''b'Hello\x85\xaa\x03'>>>>;编码器。encoder(B'Hello\x85\x85\xaa\x03'''>>
>>>>
>>>>>>>/>b“你好”
````
7816-4
*pypadding.iso7816\u 4
*pypadding从“b'\x80”开始,用零“b'\x00'`
*例如,当块大小为8时,b'hello'需要3字节到块大小的倍数-->;将第一个字节填充到“b'\x80'\x80'`然后填充到“b'\x00'`(`b'hello\x80\x00\x00\x00\x00'`)
>python从pypadding导入iso7816\u 4\x00'`>br/>>br/>>
>;>;编码器=ISO7816\u 4.encoder()
>>;编码器编码(b'hello')
b'hello\x80\x00\x00\x00'
>>;gt;gt;>;编码器解码(b'hello\x80\x00\x00\x00')
b'hello'
```
>
;设置块大小
>```python
>>;从pypaddpadding导入pkcs
>>>;设置块大小
>>```python
>>>;gt;gt;>gt;从pypaddpaddpadding导入pkcs
>>>>;>;编码器=pkcs.编码器(16)
>;>;编码器。编码器。编码器(b'blackjack')
b'blackjack\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07'
>;gt;gt;gt;编码器。解码(b'blackjack\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\gt;)
b'blackjack'
````>>>`````
>>>>
>>>
>>>>cs.编码器(块大小=16)
>;>;编码器。编码器。编码(b'blackjack')
b'blackjack\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07'
>;gt;gt;gt;gt;编码器。解码(b'blackjack\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07’)
b'blackjack'
````
;注意
*所有编码的数据都有填充,即使原始数据的长度是块大小的倍数,块大小的倍数,原始.block size=8,编码w/pkcs,` encode('computer')`-->;`B'计算机\x08\x08\x08\x08\x08\x08\x08\x08'`
\reference
*https://en.wikipedia.org/wiki/padding(密码学)
*此包仅实现可逆方法
[![构建状态](https://travis-ci.org/blinglnav/pypadding.svg?(https://travis ci.org/blinglnav/pypadding)
>该包实现了使用块密码函数的填充方法。
*例如,当块大小为8时,b'hello'需要3个字节对于块大小的倍数-->;使用“b”\x03`(`b'hello\x03\x03\x03`)
``python
>;>pypadding import pkcs
>;>encoder=pkcs.encoder()
>;>encoder.encode(b'hello')
b'hello\x03\x03'
>;>编码器。解码(b'hello\x03\x03\x03')
b'hello'
````
```ansi x923
*pypadding.x923
*使用零填充(`b'\x00'`),最后一个字节设置为填充长度
*例如,当块大小为8时,b'hello'需要3个字节到块大小的倍数-->;使用“b”\x00'填充,最后一个字节设置为“b”\x03'`(`b'hello\x00\x00\x03'`)
``` python
>;>>;从pypadding导入x923
>;>encoder=x923.encoder()
>;>encoder.encode(b'hello')
b'hello\x00\x03'
>;>编码器。解码(b'hello\x00\x00\x03')
b'hello'
`````
iso 10126
*pypadding.iso10126
*使用随机字节填充,最后一个字节设置为padding长度
*例如,当块大小为8时,b'hello'需要3个字节到块大小的倍数-->;将随机字节和最后字节填充为“B'\x03'`(`B'Hello\x85\x85\xaa\x03'`B'Hello\x85\xaa\xx03'`)
>`python
>;从PyPadding导入iso10126
>;>gt;encoder=iso10126.encoder()
>;编码器。encode(B'Hello')
B'Hello\x85\xaa\x03''b'Hello\x85\xaa\x03'>>>>;编码器。encoder(B'Hello\x85\x85\xaa\x03'''>>
>>>>
>>>>>>>/>b“你好”
````
7816-4
*pypadding.iso7816\u 4
*pypadding从“b'\x80”开始,用零“b'\x00'`
*例如,当块大小为8时,b'hello'需要3字节到块大小的倍数-->;将第一个字节填充到“b'\x80'\x80'`然后填充到“b'\x00'`(`b'hello\x80\x00\x00\x00\x00'`)
>python从pypadding导入iso7816\u 4\x00'`>br/>>br/>>
>;>;编码器=ISO7816\u 4.encoder()
>>;编码器编码(b'hello')
b'hello\x80\x00\x00\x00'
>>;gt;gt;>;编码器解码(b'hello\x80\x00\x00\x00')
b'hello'
```
>
;设置块大小
>```python
>>;从pypaddpadding导入pkcs
>>>;设置块大小
>>```python
>>>;gt;gt;>gt;从pypaddpaddpadding导入pkcs
>>>>;>;编码器=pkcs.编码器(16)
>;>;编码器。编码器。编码器(b'blackjack')
b'blackjack\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07'
>;gt;gt;gt;编码器。解码(b'blackjack\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\gt;)
b'blackjack'
````>>>`````
>>>>
>>>
>>>>cs.编码器(块大小=16)
>;>;编码器。编码器。编码(b'blackjack')
b'blackjack\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07'
>;gt;gt;gt;gt;编码器。解码(b'blackjack\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07’)
b'blackjack'
````
;注意
*所有编码的数据都有填充,即使原始数据的长度是块大小的倍数,块大小的倍数,原始.block size=8,编码w/pkcs,` encode('computer')`-->;`B'计算机\x08\x08\x08\x08\x08\x08\x08\x08'`
\reference
*https://en.wikipedia.org/wiki/padding(密码学)
*此包仅实现可逆方法