A developing toolkit for RSA and AES encryption and decryption under test
Execute the following command to get the latest version of the package:
composer require jybtx/rsa-crypt-aes
ServiceProvider will be attached automatically
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,
]
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
use RsaCryptAes;
$public = RsaCryptAes::getThePublicKey();
$random = RsaCryptAes::decryptRandomString($obj,$md5PublicKey);
$data = RsaCryptAes::getDecryptEncryptedData($random,$pubKeyMd5,$data);
if ( $data == FALSE ) return respone()->json(['status'=>100,'message'=>'Public key invalidation, retrieve']);
return RsaCryptAes::getReturnEncryptDataForApi($status,$msg,$data='');
// Return data format
return [
'status' => $status,
'msg' => $msg,
'data' => $data,
'sign' => $encrypt_aes_key,
];
$restart = RsaCryptAes::getEncryptedDataAndRandomStrings($status,$msg,$data);
return [
'status' => $status,
'msg' => $msg,
'data' => $string,
'random' => $encrypt_aes_key,
'md5public' => md5($pubKey)
];
$result = RsaCryptAes::getSign(string $attributes,$private_key);
return (string) Signature;
$result = RsaCryptAes::getVerify(string $attributes, string $sign, $publicKey);
return boolean true | false;
Tips:The encryption and decryption of RSA and AES still need to be improved, but it does not affect the normal use
MIT