I am using CI's own encryption and need confirmation about key length used by AES-256 with CBC. I am using both 32 Bytes and 64 Bytes, and all is working. How about using a 128 Bytes (1024 bits) key?
-
Possible duplicate of [How to choose an AES encryption mode (CBC ECB CTR OCB CFB)?](http://stackoverflow.com/questions/1220751/how-to-choose-an-aes-encryption-mode-cbc-ecb-ctr-ocb-cfb) – Surya Tanamas Feb 08 '17 at 04:34
2 Answers
AES has a fixed block size of 128 bit and supports key sizes of 128, 192 and 256 bit. It does not support key sizes of 512 bit (64 byte). Rijndael, which AES is based on, supports block sizes of 128, 192 and 256 bit with the same key sizes as AES.
If you're using system/libraries/Encrypt.php, then you're using Rijndael-256 (default; not AES, because the block size (256) is different) with a key size of 256 bit. Every "key" that you pass in will be hashed with MD5 which is actually only 128 bit in size, but it is Hex-encoded and therefore needlessly inflated to 256 bit without extra security. Needless to say, this is rather old and should never be used anymore.
If you're using system/libraries/Encryption.php, then you're using AES-128 (here 128 actually means the key size) with authentication. The key that you pass in is used for both encryption and authentication. The encryption key is derived from the passed key through HKDF with HMAC-SHA512, so it will be effectively hashed and then clamped to 128 bit. You should still need to pass at least 16 byte keys in to have 128 bit security.
Although the key is hashed in both cases to get the appropriate size (it's actually bigger, but the underlying drivers take only the first byte that they need), don't try to pass in passwords, because they have much less entropy than real randomly generated keys of at least 16 bytes.
How about using a 128 Bytes (1024 bits) key?
This wouldn't give you more security, because the actual encryption key that is derived from the key you pass in is actually only 256 bit long.

- 61,146
- 24
- 125
- 222
-
so it don't used if i try using hkdf with sha512 that produce 64 bytes keys ?? – Surya Tanamas Nov 24 '15 at 16:06
-
Exactly, using keys larger than 16 bytes won't give you any additional security. I've checked with the way `openssl_encrypt` behaves and it will actually use AES-128 if "aes-128" was requested which is the default (unchangeable) for the second CI class. – Artjom B. Nov 24 '15 at 16:39
When you use AES-256. It has
Minimum of Strength - 256
Factoring Modulus - 15360
Hash (A) - SHA-512
Hash (B) - SHA-256/SHA-384/SHA-512
Read this article as well http://www.keylength.com

- 36,589
- 17
- 64
- 85
-
-
-
ok so using 512 bit key length is maximum. And don't using SHA to create bigger key, i am using php-ci own random chat generator. – Surya Tanamas Nov 24 '15 at 05:03
-