custom-d / eloquent-async-keys
A eloquent async keys
Requires
- php: ^8.1
- ext-openssl: *
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- larastan/larastan: ^2.0
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.5|^10.0
This package is auto-updated.
Last update: 2024-11-07 02:09:25 UTC
README
Package to handle public private keys for your application and other uses, stored in a rsa_keystore
model which can be linked to any other model.
Installation
Install via composer
composer require custom-d/eloquent-async-keys
Register Service Provider
Note! This and next step are optional if you use laravel>=5.5 with package auto discovery feature.
Add service provider to config/app.php
in providers
section
CustomD\EloquentAsyncKeys\ServiceProvider::class,
Register Facade (optional)
Register package facade in config/app.php
in aliases
section
CustomD\EloquentAsyncKeys\Facades\EloquentAsyncKeys::class,
Publish Configuration File & generate global key
php artisan vendor:publish --provider="CustomD\EloquentAsyncKeys\ServiceProvider" --tag="config"
php artisan asynckey
Usage
namespace CustomD\EloquentAsyncKeys;
EloquentAsyncKeys::create([$keySize = null], [$overwrite = false]): self
- This allows you to create a new set of keys and returns an instance of the class.EloquentAsyncKeys::encrypt($data, [$version = null]): array
- this allows you to encrypt a new message and optionally set then algorithm versionEloquentAsyncKeys::encryptWithKey($publicKey, $data, [$version = null]): array
- this allows you to encrypt a new message with a provided key and optionally set then algorithm versionEloquentAsyncKeys::decrypt($data, [$key = null]): string
- Decrypts the messageEloquentAsyncKeys::decryptWithKey($privateKey, $data, $key = null): string
- this allows you to decrypt a message with a provided keyEloquentAsyncKeys::getPublicKey(): string
- gets the current public keyEloquentAsyncKeys::getPrivateKey(): string
- gets the current private keyEloquentAsyncKeys::getSalt(): string
- gets the current saltEloquentAsyncKeys::getDecryptedPrivateKey(): resource
- gets the current decrypted private keyEloquentAsyncKeys::setKeys([$publicKey = null], [$privateKey = null], [$password = null]): self
- set the public, private and passwordEloquentAsyncKeys::setPublicKey(?string $publicKey = null): self
- sets/unsets the public keyEloquentAsyncKeys::setPrivateKey(?string $privateKey = null): self
- sets/unsets the private keyEloquentAsyncKeys::setSalt($salt = null): self
- sets/unsets/generates salt, (pass true to generate a new salt)EloquentAsyncKeys::setPassword(?string $password = null): self
- set/unset the password for the current private keyEloquentAsyncKeys::setNewPassword(string $newPassword, $newSalt = false): void
- sets a new password onto your current privateKey
Included for tinker / phpunit / seeds
We have added a faker library to use to populate your keystores:
use CustomD\EloquentAsyncKeys\Faker\Keygen;
...
$faker = Factory::create(Factory::DEFAULT_LOCALE);
$faker->addProvider(new Keygen($faker));
$keyset = $faker->keygenCollection($faker->password(), true);
will return your with keyset as an array containing the following structure
[
'password' => x,
'salt' => x,
'publicKey' => x,
'privateKey' => x
]
.
Security
If you discover any security related issues, please email instead of using the issue tracker.