cancel
Showing results for 
Search instead for 
Did you mean: 

Why the STM32_AES_CBC_Encrypt function doesn't return multiple of 64 bytes encrypted message

emil28
Senior

Hi,

I am using the function STM32_AES_CBC_Encrypt from the ST library Crypto 3.1.0. I don't understand why this function doesn't give me an encrypted message which is a multiple of 64 bytes.

For example, I would like to encrypt "thisisatest12345". The function returns a tab which is the same size of the original tab:

0693W000004ImLsQAK.jpg

Thes encrypted message is "0x1E 0xDD 0x1B 0x2A 0x8B 0xA6 0xDC 0x5E 0xBE 0xD6 0x9D 0x78 0xA4 0xA9 0xCA 0x3B ". Following the website https://www.devglan.com/online-tools/aes-encryption-decryption, the encypted message should be "1EDD1B2A8BA6DC5EBED69D78A4A9CA3B813290DF65F7ABD59239929768C8603F", which is 64 bytes. But, when I transform the encrypted message into Base 64, I have the same result as the previsous website, but there is a missing part:

From website;

0693W000004ImRgQAK.jpg

From my code:

0693W000004ImRDQA0.jpg

The beginning is the same, but a part is missing, and I don't know why.

Can you help me, I don't know how to solve this problem.

Thanks.

12 REPLIES 12
RamaKrishna
Associate II

Hi,

Iam having same issue what emil28 is facing , In simple term issue is i'm encrypting  a message "0000000012345678", when i encrypt this message using AES 128 CBC the encrypted message should be 32 bytes long like this "5BE9894C93D9B6D72A7C83512076166AC615BCDCED48486723B6D845788DB15E"  but function "STM32_AES_CBC_Encrypt" is returning only 16 bytes  "5BE9894C93D9B6D72A7C83512076166A"  which is only half of 32 bytes, using this 16 bytes we cannot decrypt the message it gives error. am I missing something in setup?

Jocelyn RICARD
ST Employee

Hello @RamaKrishna,

As stated earlier, AES is based on 16 bytes blocks. So, you should never get 32 bytes when encrypting less than 16 bytes.

Best regards

Jocelyn

Hi,

Ok thanks got it, it looks like online tools using some padding mechanisms (pkcs7 and pkcs5 ) and so even if we are giving 16 bytes we are getting 32 bytes output.