Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there ,
I'm trying to use the AES Class within Visual C#
While coding a message, it occcured to me that trying to encode a 16 bytes Block message with AES give 2*16 bytes encrypted blocks ( like my message was 32 bytes long).
It does the same for 2* 16 bytes blocks messages, where 3*16 bytes encrypted blocks are returned.

I'm using an IV and a key of 16 bytes (128 bits).
If i send 15 bytes, the encrypted message turns back to 16 bytes again ( 15 bytes message + PKCS Padding realised internally within the class)

Inside the AES specification document, it is not clarly stated if a char is added to endup the message , before realising the padding , but i suspect this to be the case , which would explain why my 16 bytes message would in fact be postponed with a termination char , and then the padding added to make it a 32 bytes message.

I read somewhere (but dont remeber the source) that before padding the message, it is recommended to add 0X80 at the end of the message.

Could someone help me to clarify why i observe the described behaviour ( 2 encryption block with one message block) ?

thanks,
Eric

What I have tried:

please see above for the description of the problem.
Posted
Comments
George Swan 3-Jul-19 1:38am    
Isn't the additional block due to the salt value being stored along with the hashed message?
Member eric67 3-Jul-19 16:54pm    
Hi George,
not there isn't any salt used so far. I directly input the key of 16 bytes "manually" for test purposes.

I figured out myself why the encrypted message is 1 block longer when 16 bytes are input in the message . This has to do with the PKCS7 padding mode that requiees the padding always to add at least 1 bytes data at the end of the message, thus if the message is 16 bytes long, at least 1 byte padding is added ( 16 bytes int htis case actually to make Message.Length mod 16 == 0).

That explains it.

Thnaks for your suggestion anyway

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900