Shaikh Azhar Alam
Shaikh Azhar Alam

Reputation: 165

AES 256 character length

I am encrypting data using AES 256 encryption, want to know how can i restrict length of the encrypted text. if i encrypt 6 character string using AES 256 it gets encrypted around 100 character. I want to add this data in table so wanted to know the maximum length so that i can set constraint in table in php codeigniter.

$this->encryption->initialize(
                array(
                'cipher' => 'aes-256',
                'mode' => 'ECB',
                'key' => $key1
                )
            ); 

$this->encryption->encrypt($_POST['uname']);

Upvotes: 1

Views: 2420

Answers (1)

zaph
zaph

Reputation: 112855

Best guess given minimal information is that you are treating encrypted data as a null terminated character string and since the encryption does not null terminate the encrypted data the null terminator is something that just happens to be in memory falling the encrypted data.

The following assume AES in ECB mode.

  1. AES does not encrypt characters, it encrypts data bytes. If you are trying to handle the encrypted output as characters that is incorrect and will generally produce errors. It character output is required the encrypted data needs to be encoded, generally with Base64 or hexadecimal.
  2. AES is a block cipher and as such the output will always be a multiple of the block length, 16-bytes for AES.
  3. If the input is not an exact multiple of the block size it needs to e padded, PKCS#7 is the generally used padding.
  4. Data encrypted with AES will be at most one block length larger than the input due to padding.

Upvotes: 1

Related Questions