dhuertas / AES

AES algorithm implementation in C
MIT License
615 stars 323 forks source link

How to aes encrypt more than 16 bytes of data #9

Closed chandan-crsl closed 2 years ago

chandan-crsl commented 2 years ago

Hi all,

I need help in encrypting more than 16 bytes of data at a time and number of bytes is not multiple of 4. Please help me how can I do it.

If I pass data more than 16 bytes, it is encrypting and decrypting only 16 bytes of data. I am using 256-bit key.

<-- Plaintext message: --> 30 81 87 02 01 00 30 13 06 07 2a 86 48 ce 3d 02 01 06 08 2a 86 48 ce 3d 03 01 07 04 6d 30 6b 02 01 01 04 20 de 44 7e 52 39 ad cc 4a 15 b5 16 41 36 17 18 a3 9a 9a 9a 8b 19 5e 1e 74 cd f5 8e 86 f4 cb a9 d5 a1 44 03 42 00 04 af 10 95 51 b7 a5 4f e7 9b 94 71 e6 a3 8f fc 27 0a b3 a1 11 f8 12 cd 11 34 6d df 40 c1 2a ce 75 23 e3 8c 9d 37 d6 10 cf 4d 13 28 86 fd fb de 3f e8 66 64 64 7b 35 22 c1 53 99 ff 29 44 5e 8b ef Ciphered message: 79 5b d0 b0 45 30 2c 84 fa 4d 89 57 f2 52 1b e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Original message (after inv cipher): 30 81 87 02 01 00 30 13 06 07 2a 86 48 ce 3d 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

dhuertas commented 2 years ago

Hi @chandan-crsl,

On its own, AES is just a block cipher algorithm, meaning it is designed to cipher blocks of 16 bytes (128 bits), one block at a time. To cipher more than one block of data, you need to use a block cipher mode of operation.

Check this Wikipedia article to know more.

You can also check this other repo of mine here, where I implemented in C some of the modes of operation detailed in the Wikipedia article.