如何在EBC模式下使用加密方法3des在phpseclib中添加零字节填充?
这是我当前的代码:
$cipher = new TripleDES(TripleDES::MODE_ECB);
$cipher->setKey('1234567890ABCDEFGHIJKLMN');
答案 0 :(得分:2)
只需弄清楚:
禁用填充:
$cipher->disablePadding();
手动填充消息:
$message_padded = $urlencoded;
if (strlen($message_padded) % 8) {
$message_padded = str_pad($message_padded,
strlen($message_padded) + 8 - strlen($message_padded) % 8, "\0");
}
加密:
$result = $cipher -> encrypt($message_padded);