<?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正则获取字符串中的图像src地址

<?php $str = <<<str <img src="1.jpg"/> <p>123123</p> <span>3322</span> <img ...

阅读全文

php predis 操作类库扩展

需先安装php predis 类库 详细predis 命令参考 :http://www.koukousky.com/back/1644.html <?php /** * Predis缓存驱动 * 要求安装phpredis扩展:https...

阅读全文

php imagick 水印、缩略图 图像处理类

使用前需安装 ImageMagick 客户端和 php Imagick 扩展类库 可解决上传图片在ios 下翻转的问题。 使用方法 $imagick = new \lib_image_imagick(); $width = 2...

阅读全文

欢迎留言