seffeng / laravel-rsa by seffeng

PHP laravel extension rsa
6,523
6
2
Package Data
Maintainer Username: seffeng
Maintainer Contact: save.zxf@gmail.com (seffeng)
Package Create Date: 2020-05-20
Package Last Update: 2023-06-06
Home Page: https://packagist.org/packages/seffeng/laravel-rsa
Language: PHP
License: MIT
Last Refreshed: 2024-12-15 15:20:24
Package Statistics
Total Downloads: 6,523
Monthly Downloads: 145
Daily Downloads: 1
Total Stars: 6
Total Watchers: 2
Total Forks: 1
Total Open Issues: 0

Laravel RSA

安装

# 安装
$ composer require seffeng/laravel-rsa
Laravel
# 1、生成配置文件
$ php artisan vendor:publish --tag="rsa"

# 2、生成key文件
$ php artisan rsa:generate
lumen
# 1、将以下代码段添加到 /bootstrap/app.php 文件中的 Providers 部分
$app->register(Seffeng\LaravelRSA\RSAServiceProvider::class);

# 2、生成key文件
$ php artisan rsa:generate
# /storage 目录下对应 public key 提供给客户端

示例


use Seffeng\LaravelRSA\Facades\RSA;
use Seffeng\LaravelRSA\Exceptions\RSAException;

class SiteController extends Controller
{
    public function test()
    {
        try {
            $plaintext = '123456';
            // 加密
            $entext = RSA::encrypt($plaintext);
            // 解密
            $detext = RSA::decrypt($entext);

            $message = 'a=aaa&b=bbb&c=ccc';
            // 签名
            $sign = RSA::sign($message);
            // 签名验证
            $verify = RSA::verify($message, $sign);

            var_dump(base64_encode($entext), $detext);
            var_dump(base64_encode($sign), $verify);
        } catch (RSAException $e) {
            var_dump($e->getMessage());
        } catch (\Exception $e) {
            var_dump($e->getMessage());
        }
    }
}

项目依赖

| 依赖 | 仓库地址 | 备注 | | :------------------ | :------------------------------------- | :--- | | phpseclib/phpseclib | https://github.com/phpseclib/phpseclib | 无 |

备注