Java中的AES-256加密需要多少大小的初始化向量? [英] What size of initialization vector needed for AES-256 encryption in java?

查看:1221
本文介绍了Java中的AES-256加密需要多少大小的初始化向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在CFB模式下使用AES-256加密。我必须使用32字节密钥。
但是我对初始化向量有点困惑。
AES-256应该使用多少个字节的初始化向量?
是16个字节还是32个字节?

I am using AES-256 encryption with CFB mode. I have to use 32 byte key. But I am little bit confused about the initialization vector. How many bytes of initialization vector should be used with AES-256 ? Is it 16 bytes or 32 bytes ?

任何代码示例都将受到赞赏。

Any code example will be appreciated.

推荐答案

TL; DR:CFB模式下的AES需要16字节的唯一(但不一定是随机的)IV。

TL;DR: AES in CFB mode requires a unique (but not necessarily randomized) IV of 16 bytes.

IV的大小取决于模式,但通常与块大小相同,对于AES来说,它总是 16个字节。某些模式与此不同,特别是GCM模式,它的默认大小为12个字节,但可以采用任意大小的IV-尽管强烈建议保留默认值。

The size of the IV depends on the mode, but typically it is the same size as the block size, which for AES is always 16 bytes. There are modes that differ from this, notably GCM mode which has a default size of 12 bytes but can take any sized IV - although keeping to the default is highly recommended.

但是,诸如CBC和CFB之类的老式模式只需要IV大小与块大小相同。即使CTR通常也需要16个字节,尽管原则上IV的大小可以小于16,在这种情况下,通常用零值字节正确填充IV。请注意,点击率通常使用初始计数器值进行初始化,这意味着您必须确保自己不会重复该计数器。

The old school modes such as CBC and CFB however simply require an IV of the same size as the block size. Even CTR commonly requires 16 bytes, although in principle the IV can be any size less than 16, in which case it is (again, commonly) right padded with zero valued bytes. Note that CTR is often initialized with an initial counter value which means you must make sure that the counter is not repeated yourself.

块大小无论密钥大小如何,AES的大小均为16个字节。说您拥有AES-256和32字节的密钥是多余的信息。对于AES-256,密钥大小 必须为256位或32字节。

The block size of AES is 16 bytes, whatever the key size. Saying that you have AES-256 and a key of 32 bytes is superfluous information. For AES-256 the key size must be 256 bits or 32 bytes.

CFB模式的IV(如前所述)必须始终为作为AES的16字节是128位块密码。与Rijndael密码相比,AES在块大小方面受到限制。 Rijndael可以配置为具有不同的块大小。

The IV for CFB mode - as stated earlier - must always be 16 bytes as AES is a 128 bit block cipher. AES is restricted with regards to the block size compared with the Rijndael cipher. Rijndael may be configured with different block sizes.

这篇关于Java中的AES-256加密需要多少大小的初始化向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆