方案1

直接输入 pecl install mcrypt-snapshot
此方案的好处是不用改代码

方案2

<?php
class Encrypt{

    //base64_encode(openssl_random_pseudo_bytes(32));
    public $key    = "qK37s8Sb0uTDflFsHVwfWqZpySDXo6uHJVMGC3UOJsU=";
    //echo base64_encode(openssl_random_pseudo_bytes(16));
    public $iv    = "EXWPKlAyhkCjqMQkxkkyyA==";

    public function encrypt($value){

        $encrypted = openssl_encrypt($value, 'aes-256-cbc', base64_decode($this->key), OPENSSL_RAW_DATA, base64_decode($this->iv));
        return base64_encode($encrypted);
    }

    public function decrypt($string){
        $encrypted = base64_decode($string);
        $decrypted = openssl_decrypt($encrypted, 'aes-256-cbc', base64_decode($this->key), OPENSSL_RAW_DATA, base64_decode($this->iv));
        return $decrypted;
    }
}

//测试
$encrypt = new Encrypt();

$arr = [
    'a'   =>   '1',
    'b'   =>   '2'
];
$des = $encrypt->encrypt(json_encode($arr));
echo $encrypt->decrypt($des);
?>

centos8 yum安装php7.3

执行命令 $ yum install epel-release $ rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm $ dnf install -y https://rpms...

阅读全文

php面试题

php魔术方法 __get( $property ) 当调用一个未定义的属性时访问此方法 __set( $property, $value ) 给一个未定义的属性赋值时调用 __isset( $proper...

阅读全文

php-rdkafka测试笔记

参考:https://learnku.com/articles/15176/laravel-implementation-of-kafka-message-push-and-receive-processing 安装 安装librdkafka 库 git clone https...

阅读全文

欢迎留言