EVP_DecryptFinal_ex:数据不是16字节密文上AES-256-CBC块长度的倍数

时间:2019-07-05 16:16:37

标签: php encryption openssl aes php-openssl

这是我的代码:

<?php
$e = 'eyJpdiI6IkpVS2E3c1gxOGp0N3ZudERxb0hFemc9PSIsInZhbHVlIjoiM3MrNjkrWlNjb3lRYitxMGVPVVRPUT09IiwibWFjIjoiYTZhOWRjZjM2YTlkODc3ZDRjYjU5ODAxMmE3MGI3ZDE1ZDY5NjQzM2FmNjBkNDY5MDM1Mzg5ZTlkNDVjYjBiZSJ9';

$key = str_repeat('a', 32);

$payload = (array) json_decode(base64_decode($e));
$payload = array_map('base64_decode', $payload);

$p = openssl_decrypt(
    $payload['value'],
    'AES-256-CBC',
    $key,
    OPENSSL_ZERO_PADDING,
    $payload['iv']
);

echo openssl_error_string() . "\n";

var_dump($p);

$payload['value']$payload['iv']一样长16个字节。 AES的块大小也是16个字节,所以我不明白为什么会收到“ 数据不是块长度的倍数”错误...

0 个答案:

没有答案