PHP code example of bytesfield / key-manager

1. Go to this page and download the library: Download bytesfield/key-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bytesfield / key-manager example snippets


'providers' => [
    ...
    Bytesfield\KeyManager\KeyManagerServiceProvider::class,
    ...
]

'aliases' => [
    ...
    'KeyManager' => Bytesfield\KeyManager\Facades\KeyManager::class,
    ...
]



return [

    /**
     * Generated API Encryption Key
     *
     */
    'api_encryption_key' => env('API_ENCRYPTION_KEY'),

];

API_ENCRYPTION_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


use Bytesfield\KeyManager\Facades\KeyManager;


KeyManager::createClient(string $name, string $type);
// Optional
KeyManager::createClient(string $name, string $type, string $status);

KeyManager::getPrivateKey(int $clientId);

KeyManager::changeKeys(int $clientId);

KeyManager::suspendClient(int $clientId);

KeyManager::activateClient(int $clientId);

KeyManager::suspendApiCredential(int $clientId);

KeyManager::activateApiCredential(int $clientId);

use Bytesfield\KeyManager\KeyManager;

public function __construct(KeyManager $keyManager)
{
    $this->keyManager = $keyManager;
}

use Bytesfield\KeyManager\KeyManagerInterface;

public function __construct(KeyManagerInterface $keyManager)
{
    $this->keyManager = $keyManager;
}


$this->keyManager->createClient(string $name, string $type);
// Optional
$this->keyManager->createClient(string $name, string $type, string $status);

$this->keyManager->getPrivateKey(int $clientId);

$this->keyManager->changeKeys(int $clientId);

$this->keyManager->suspendClient(int $clientId);

$this->keyManager->activateClient(int $clientId);

$this->keyManager->suspendApiCredential(int $clientId);

$this->keyManager->activateApiCredential(int $clientId);

Route::get('test', function(){
    return "Hello world";
})->middleware('auth.client');

public function __construct(){
    $this->middleware('auth.client');
}
bash
php artisan key-manager:install
bash
php artisan migrate
bash
php artisan encryption:generate
bash
client:suspend-key {clientId}
bash
client:activate-key {clientId}