phpseclib零字节填充

时间:2019-02-25 05:51:02

标签: php encryption phpseclib 3des

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

这是我当前的代码:

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

1 个答案:

答案 0 :(得分:2)

只需弄清楚:

  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, "\0");
    }
    
  3. 加密:

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