phpseclib 零字节填充

phpseclib zero byte padding

如何在EBC模式3des加密方式的phpseclib中添加零字节填充?

这是我当前的代码:

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

想明白了:

  1. 禁用填充:

    $cipher->disablePadding();
    
  2. 手动填充消息:

    $message_padded = $urlencoded;
    if (strlen($message_padded) % 8) {
        $message_padded = str_pad($message_padded,
            strlen($message_padded) + 8 - strlen($message_padded) % 8, "[=11=]");
    }
    
  3. 加密:

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