php中mcrypt_encrypt升级到openssl_encrypt

php中mcrypt_encrypt升级到openssl_encrypt

原因: php8中已经弃用 mcrypt_encrypt

详细测试代码

$account= [
    'encodeKey' => '0f5264038205EDFB1AC05fbb0e8c5e94',
    'ivKey' => '0f5264038205EDFB',
    'password' => 'testpwd',  //登陆密码
];


// 历史代码, 使用mcrypt_encrypt加密数据
echo $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $account['encodeKey'], $account['password'], MCRYPT_MODE_CBC, $account['ivKey']));
echo '
'; // error:0607F08A:digital envelope routines:EVP_EncryptFinal_ex:data not multiple of block length // 要加密的数据长度不是密钥长度的倍数 $pwd = $account['password']; while (strlen($pwd)%16 != 0){ $pwd = $pwd."\x0"; } // 使用openssl_encrypt加密base64编码后的数据 $encrypted_openssl = openssl_encrypt($pwd, 'AES-256-CBC', $account['encodeKey'], OPENSSL_ZERO_PADDING, $account['ivKey']); // var_dump('error: '.openssl_error_string()); echo $encrypted_openssl;

你可能感兴趣的:(php,开发语言)