Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AES algorithm input and output restrictions

Tags:

aes

I want to use AES encryption in my application. I have come across some open source implementations of aes algorithm. By looking at them, I am confused about the following parameters:

  1. AES key length. It is mentioned that key length should be 128, 192 or 256 bytes. What if my key is simply five digits i.e. 23467

  2. AES plain-text length : is there any restriction on the aes plain-text length ?

  3. AES output: What would be the minimum size of aes output string if my key length is say 5 digits and plain-text is say 10 characters.

Can anyone help me?

like image 232
cppdev Avatar asked Dec 21 '22 19:12

cppdev


1 Answers

AES key length. It is mentioned that key length should be 128, 192 or 256 bits. What if my key is simply five digits i.e. 23467

It seems you're thinking of the key as a password of sorts. It isn't. A cryptographic key isn't meant to be memorized. It is a long string of randomly generated bytes that should be stored somewhere safe.

You can derivate a cryptographic key from a password, though, for instance using a hash function. In that case you input 234567 and use the resulting digest as the key. This has some security implications, however, as it makes your key vulnerable to dictionary and rainbow table attacks. Look up "password based encryption" for details on how to approach this securely; in particular, have a look at PBKDF2, described in RFC2898.

AES plain-text length : is there any restriction on the aes plain-text length ?

AES is the block cipher, the underlying building block of an encryption system. By itself it can only encrypt a single block of data (16 bytes), so cryptographers have created several "modes of operation" that enable us to encrypt a plaintext of arbitrary length. CTR is a fine example of a mode of operation that does not require any padding and can be parallelized.

AES output: What would be the minimum size of aes output string if my key length is say 5 digits and plain-text is say 10 characters.

That's entirely dependent on the mode of operation. In your case it will probably be either 10 (when no padding is required, for example with CTR) or 16 (for block-based modes such as CBC).

like image 162
Pedro d'Aquino Avatar answered Dec 31 '22 14:12

Pedro d'Aquino