使用des加密出现Call to undefined function: mcrypt_module_open()


php7.2之前使用mcrypt,之后直接启用了openssl_encryptopenssl_decrypt

什么libsodium啊,什么Unknown cipher algorithm啊,什么configure: error: mcrypt.h not found绕晕了

这两个方法直接ide可以看到用法,简单问题复杂化了,还是缺少学习。

嫁接加密和解密方法


    /**
     * @param $data 需要加密的明文数据
     * @param $method 模式:DES-ECB/DES-CBC/DES-CTR/DES-OFB/DES-CFB
     * @param $key 加密密钥passwd
     * @param int $options 数据格式选项[0,1,2,3] OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING|OPENSSL_NO_PADDING
     * @param string $iv 加密初始化向量
     * @param null $tag
     * @param string $aad
     * @param int $tag_length
     * @return string
     */
    public static function desEncode($data, $method, $key, $options = 0, $iv = "", &$tag = NULL, $aad = "", $tag_length = 16)
    {
        return openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length);
    }

    /**
     * 需要解密的密文
     */
    public static function desDecode($data, $method, $password, $options = 1, $iv = "", $tag = "", $aad = "")
    {
        return openssl_decrypt($data, $method, $password, $options, $iv, $tag, $aad);
    }

其它笔记,启用 pecl(The PHP Extension Community Library)

http://pecl.php.net/packages.php

yum -y install php-pear
yum -y install php-devel
yum install -y epel-release
yum install -y libmcrypt-devel
yum -y install php php-devel php-pear

pecl install mcrypt

php -i | grep mcrypt
php -m | grep mcrypt

原文链接:https://blog.yongit.com/note/853916.html