aes256 java,Java中的AES-256加密需要多少大小的初始化向量?

AES-256在CFB模式下使用时,需要一个16字节的初始化向量(IV)。尽管密钥是32字节,但IV的大小与AES的128位(16字节)块大小相同。对于CFB模式,无论密钥尺寸如何,IV始终为16字节。
摘要由CSDN通过智能技术生成

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: AES in CFB mode requires a unique (but not necessarily randomized) IV of 16 bytes.

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.

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.

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.

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值