首页 > 解决方案 > 为什么 Openssl 使用 openssl_decrypt 函数抛出错误?

问题描述

我收到此错误,但我不知道为什么。

openssl_decrypt(): IV 传递只有 8 字节长,密码期望 IV 正好 16 字节,用 \0 填充

我认为这是一个长度错误,但不确定。

功能

public static function decrypt($ciphertext) {

            $iv_size = openssl_cipher_iv_length('AES-128-CBC');
            $iv = substr(base64_decode($ciphertext), 0, $iv_size);
            $ciphertext = substr(base64_decode($ciphertext), $iv_size);

            $dec = openssl_decrypt($ciphertext, 'AES-128-CBC', self::key(), OPENSSL_RAW_DATA, $iv);

            return $dec;

    }

标签: phpopenssl

解决方案


推荐阅读