jybtx/rsa-crypt-aes
Composer 安装命令:
composer require jybtx/rsa-crypt-aes
包简介
This is an extension of RSA and AES encryption and decryption for API interface, which is suitable for encryption and decryption with high requirements for encrypted data
README 文档
README
A developing toolkit for RSA and AES encryption and decryption under test
Installation
Composer
Execute the following command to get the latest version of the package:
composer require jybtx/rsa-crypt-aes
Laravel
>= laravel5.5
ServiceProvider will be attached automatically
Other
In your config/app.php add Jybtx\RsaCryptAes\Providers\CryptServiceProvider::class to the end of the providers array:
'providers' => [ ... Jybtx\RsaCryptAes\Providers\CryptServiceProvider::class, ], 'aliases' => [ ... "RsaCryptAes" => Jybtx\RsaCryptAes\Faceds\RsaCryptAesFaced::class, ]
Generate secret key
I have included a helper command to generate a key for you:
php artisan jybtx:secret
This will update your .env file with something like HEX_IV=foobar
It is the key that will be used to sign your tokens. How that happens exactly will depend on the algorithm that you choose to use.
Publish Configuration
php artisan vendor:publish --provider "Jybtx\RsaCryptAes\Providers\CryptServiceProvider"
OR
php artisan vendor:publish --tag=crypt
Usage
get a public key
use RsaCryptAes; $public = RsaCryptAes::getThePublicKey();
decrypt Random String
$random = RsaCryptAes::decryptRandomString($obj,$md5PublicKey);
decrypt Encrypted Data
$data = RsaCryptAes::getDecryptEncryptedData($random,$pubKeyMd5,$data); if ( $data == FALSE ) return respone()->json(['status'=>100,'message'=>'Public key invalidation, retrieve']);
return data for api
return RsaCryptAes::getReturnEncryptDataForApi($status,$msg,$data=''); // Return data format return [ 'status' => $status, 'msg' => $msg, 'data' => $data, 'sign' => $encrypt_aes_key, ];
encrypt Data
$restart = RsaCryptAes::getEncryptedDataAndRandomStrings($status,$msg,$data); return [ 'status' => $status, 'msg' => $msg, 'data' => $string, 'random' => $encrypt_aes_key, 'md5public' => md5($pubKey) ];
Signature operation
$result = RsaCryptAes::getSign(string $attributes,$private_key); return (string) Signature;
Signature verification
$result = RsaCryptAes::getVerify(string $attributes, string $sign, $publicKey); return boolean true | false;
Last
Tips:The encryption and decryption of RSA and AES still need to be improved, but it does not affect the normal use
License
MIT
统计信息
- 总下载量: 670
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-09-21