Bill
Bill

Reputation: 19308

PHP AES encryption padding NULL

I am try to setup an AES encryption.

And i am using the following lib, it works great.

http://www.coderelic.com/examples/AES_Encryption_Example.php

However the external business told me to use padding NULL, i have no idea

  3 = Pad with NULLs. (If already a multiple of the algorithm's block
  size, no padding is added).

I have totally lost and there is no Pad with NULL in the lib class as well, is there anyone can help, seriously i am clueless. Any suggestion or help appreciate.

Upvotes: 0

Views: 424

Answers (1)

rra
rra

Reputation: 3887

The code you're using is already doing that. See the start of AES_Encryption.php:

The default padding method in this AES_Encryption class is ZERO padding ZERO padding is generally OK for paddings in messages because null bytes stripped at the end of a readable message should not hurt the point of the text. If you are concerned about message integrity, you can use PKCS7 instead

Background: AES, like many encryption algorithms, is a block cipher. That means it can only encrypt data that is exactly the length of its block. You have to decide on a padding technique to pad out your data to exactly the block size before you encrypt it. But any decent low-level encryption library will take care of details like this. You do have to know the padding technique on decryption or otherwise have a way of recovering the original length so that you don't consider the padding to be part of the data, which is why the external business is specifying the padding method.

By pad with NULLs, they almost certainly mean pad with nul bytes (NULL and nul, so often confused), which is what AES_Encryption calls ZERO padding.

Upvotes: 1

Related Questions