Search code examples
cryptographyaes

AES-128 What padding method is used in this cipher example?


I have just implemented an AES-128 encryption algorithm, with the following message and key.

Message: "Two One Nine Two" (128 bits)

Key: "Thats my Kung Fu" (128 bits)

The cipher output for this is :

29c3505f571420f6402299b31a02d73a

which is correct when I cross-checked with online generators.

However, the online generator output is usually longer :

29c3505f571420f6402299b31a02d73ab3e46f11ba8d2b97c18769449a89e868

I tried several padding methods (bit, zerolength, cms, null, space) but nothing seems to produce exactly the b3e46f11ba8d2b97c18769449a89e868 part of the crypt text.

Could anyone help to explain what padding method (in binary) is used to produce those numbers, please?


Solution

  • Thank you @Topaco, the padding is indeed PKCS7. In this case, since the input is exactly 128 bit, an extra padding block of 128 bit must be appended, consisting of 16 bytes of the value 16 each:

    00010000 000010000 00010000 00010000 00010000.... (x16)
    

    This gives the correct crypt text

    b3e46f11ba8d2b97c18769449a89e868
    

    for the key in this example.