Skip to content

Encryption padding #3

@bjun626

Description

@bjun626

It seems like the char after NULL(\0) are filled with random values. This means there will be error when decrypting using the online tools e.g. Calculator
According to Using Padding in Encryption

We need to pad the block with padding bytes to make it up to the required length. There are at least five common conventions:-

Pad with bytes all of the same value as the number of padding bytes
Pad with 0x80 followed by zero bytes
Pad with zeroes except make the last byte equal to the number of padding bytes
Pad with zero (null) characters
Pad with space characters

Could consider adding this code at line 155

if( plainText.length()%BUFF_SIZE > 0 ) {    
  for(int bytes_read=(index*BUFF_SIZE); bytes_read <= (index*BUFF_SIZE) + plainText.length()%BUFF_SIZE; bytes_read++) {
    buffer += plainText[bytes_read];
  };
  ////ADDITIONAL CODE////
  int no_to_pad = 16 - buffer.length(); 
  while (buffer.length() < 16) {
    char padding = no_to_pad;
    buffer += padding;
  }
  ////////////////////////
  cipherTextString += encryptBuffer(const_cast<char*>(buffer.c_str()), key);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions