1 Padding :
string text;
int len = text.size();
char chT = (AES_BLOCK_SIZE - len%AES_BLOCK_SIZE);
for (int i = 0; i< (AES_BLOCK_SIZE - len%AES_BLOCK_SIZE); i++)
{
text.push_back(chT);
}
2 UnPadding:
char chT = out[len-1];
for (int i = 0; i < chT; i++)
{
if (out[len - i -1] != chT)
{
return len;
}
}
The padding will be one of:
01 02 02 03 03 03 04 04 04 04 05 05 05 05 05 etc.
This padding method (as well as the previous two) is well-defined if and only if N is less than 256.
Example: In the following example the block size is 8 bytes and padding is required for 4 bytes
... | DD DD DD DD DD DD DD DD | DD DD DD DD 04 04 04 04 |