首页 新闻 搜索 专区 学院

关于 Java 的PKCS5Padding与C# 的PKCS7Padding的区别

0
悬赏园豆:5 [已解决问题] 解决于 2015-08-26 11:20

aes加密,C# 默认PKCS7Padding与Java的PKCS5Padding,不是太了解,哪位老师能给点意见吗?

老三的古代的主页 老三的古代 | 初学一级 | 园豆:184
提问于:2015-06-30 09:57
< >
分享
最佳答案
0

推荐园子里的一篇博文:关于PKCS5Padding与PKCS7Padding的区别

收获园豆:5
dudu | 高人七级 |园豆:39034 | 2015-06-30 10:22

多谢,文章已看能否给出aes加密方法能让C#和Java通过。

老三的古代 | 园豆:184 (初学一级) | 2015-06-30 10:25

@老三的古代: 是想实现Java中AES加密,C#中ACE解密或者反之吗?

dudu | 园豆:39034 (高人七级) | 2015-06-30 10:30

@dudu: 是的,现在两方出现不对称的情况.

老三的古代 | 园豆:184 (初学一级) | 2015-06-30 11:03

@老三的古代: 试试AES Crypt

dudu | 园豆:39034 (高人七级) | 2015-06-30 11:11

@dudu: 多谢,目前采用无偏移解决问题,但是降低了复杂度,先这样吧。

老三的古代 | 园豆:184 (初学一级) | 2015-07-02 15:59
其他回答(1)
0

PKCS7[edit]

PKCS#7 is described in RFC 5652.

Padding is in whole bytes. The value of each added byte is the number of bytes that are added, i.e. N bytes, each of value N are added. The number of bytes added will depend on the block boundary to which the message needs to be extended.

The padding will be one of:

01 02 02 03 03 03 04 04 04 04 05 05 05 05 05 etc.

This padding method (as well as the previous two) is well-defined if and only if N is less than 256.

Example: In the following example the block size is 8 bytes and padding is required for 4 bytes

... | DD DD DD DD DD DD DD DD | DD DD DD DD 04 04 04 04 |

If the original data is a multiple of N bytes, then an extra block of bytes with value N is added.

PKCS#5 padding is identical to PKCS#7 padding, except that it has only been defined for block ciphers that use a 64-bit (8 byte) block size. In practice the two can be used interchangeably.

Launcher | 园豆:45045 (高人七级) | 2015-06-30 10:09

看不懂,用机器翻译了一下。

支持(0) 反对(0) 老三的古代 | 园豆:184 (初学一级) | 2015-06-30 10:24

@老三的古代: 最简单的情况,如果加密操作的块大小为 64 位(8字节)时,PKCS#5 同 PKCS#7 填充结果一致。

支持(0) 反对(0) Launcher | 园豆:45045 (高人七级) | 2015-06-30 10:46

@Launcher: 多谢.

支持(0) 反对(0) 老三的古代 | 园豆:184 (初学一级) | 2015-06-30 11:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册