shaozeming/laravel-crypt

一个签名/验签,加密解密的laravel/lumen包

v0.0.4 2020-03-18 16:01 UTC

This package is auto-updated.

Last update: 2024-12-19 02:02:17 UTC


README

Installing

$ composer require shaozeming/laravel-crypt -v

Laravel

// config/app.php

    'providers' => [
        //...
        ShaoZeMing\LaravelCrypt\CryptServiceProvider::class,    //This is default in laravel 5.5
    ],

And publish the config file:

$ php artisan vendor:publish --provider=ShaoZeMing\\LaravelCrypt\\CryptServiceProvider

if you want to use facade mode, you can register a facade name what you want to use, for example crypt:

// config/app.php

    'aliases' => [
        'MingCrypt' => ShaoZeMing\LaravelCrypt\Facade\Crypt::class,   //This is default in laravel 5.5
    ],

lumen

  • 在 bootstrap/app.php 中 82 行左右:
$app->register( ShaoZeMing\LaravelCrypt\CryptServiceProvider::class);

vendor/ShaoZeMing/laravel-crypt/config/crypt.php 拷贝到项目根目录/config目录下,并将文件名改成crypt.php

configuration

// config/crypt.php

    
    /**
     * 本项目的app_secret
     */
    'app_secret' =>env('XTHK_APP_SECRET','12345678912345678912345678912312'),

    /**
     * 加密规则,支持AES-128-CBC,AES-256-CBC
     */
    'cipher' => env('XTHK_CIPHER','AES-256-CBC'),

Usage


Example:

use ShaoZeMing\LaravelCrypt\Facade\Crypt;

$data = ['test'=>123];
$sign = Crypt::sign($data);   //签名
print_r($sign);
$check = Crypt::signCheck($data,$sign);   //验签
print_r($check);

$payload =  Crypt::encrypt($data);  //加密
print_r($payload);
$data = Crypt::decrypt($payload);   //解密
print_r($data);

License

MIT