<?php
/*
 *  加密解密类
 */

namespace app\common\lib\encrypt;

use Defuse\Crypto\Key;
use Defuse\Crypto\Crypto;

#使用之前需先安装 defuse/php-encryption

class CryptoKey {

    public static $key = 'def00000c489c83f378af872f8b156896bdc50c3441305b795f54c4150b21d9742e5695568a03b64c968bbfbaed295ce7e661df53232e31a2c9169d39f759a1fa1260541';

    public static function loadEncryptionKeyFromConfig() {
//        $keyAscii = '';// ... load the contents of /etc/daveapp-secret-key.txt
        return Key::loadFromAsciiSafeString(self::$key);
    }

    //加密
    public static function encrypt($str = '') {
        return Crypto::encrypt($str,self::loadEncryptionKeyFromConfig());
    }
    //解密
    public static function decrypt($str = '') {
        return Crypto::decrypt($str,self::loadEncryptionKeyFromConfig());
    }
    #生成key
    public static function createKey() {
        $key = Key::createNewRandomKey();
        echo $key->saveToAsciiSafeString(), "\n";
    }
}

php-rdkafka测试笔记

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

阅读全文

推荐一个好用的php日志类库,monolog/monolog

github仓库地址 官方文档: https://github.com/Seldaek/monolog/blob/main/doc/01-usage.md 安装 $ composer require monolog/monolog 使用方法 <?php us...

阅读全文

php 二维数组根据某个键值倒叙、升序排序

<?php $array = [ [ 'title' => '标题5', 'views' => 500 ], [ 'title&...

阅读全文

欢迎留言