ShaoZeMing / laravel-crypt by ShaoZeMing

一个签名/验签,加密解密的laravel/lumen包
6,730
0
1
Package Data
Maintainer Username: ShaoZeMing
Maintainer Contact: szm19920426@gmail.com (ShaoZeMing)
Package Create Date: 2019-07-05
Package Last Update: 2020-03-18
Language: PHP
License: MIT
Last Refreshed: 2024-11-26 15:05:29
Package Statistics
Total Downloads: 6,730
Monthly Downloads: 74
Daily Downloads: 5
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Crypt for laravel5.* or lumen


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