<?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使用生成器读取超大文件

<?php function getLines($file) { $f = fopen($file, 'r'); try { while ($line = fgets($f)) { yield $line; ...

阅读全文

php获取字符串里面的图片,xpath方式

代码 <?php $html = <<<str <html> <head> <title>123</title> </head> <body> <img src=&quo...

阅读全文

Thinkphp5 in查询结果按照in里面的顺序排

或许有人会注意过,但我以前真不知道 SQL: select * from table where id IN (3,6,9,1,2,5,8,7); 这样的情况取出来后,其实,id还是按1,2,3,4,5,6,7,8,9,排序...

阅读全文

欢迎留言