phpencryptionphpseclib3des

phpseclib zero byte padding


How to add zero byte padding in phpseclib with encryption method 3des in EBC mode?

Here my current code:

$cipher = new TripleDES(TripleDES::MODE_ECB);
$cipher->setKey('1234567890ABCDEFGHIJKLMN');

Solution

  • Just figure it out:

    1. Disable padding: <hack

      $cipher->disablePadding();
      
      
    2. Manually pad message (depending on size here I used multiple of 8): <hack

      $message_padded = $urlencoded;
      if (strlen($message_padded) % 8) {
          $message_padded = str_pad($message_padded,
              strlen($message_padded) + 8 - strlen($message_padded) % 8, "\0");
      }
      
    3. encrypt: <hack

      $result = $cipher -> encrypt($message_padded);