PHP code example of burakdalyanda / cipher-weave

1. Go to this page and download the library: Download burakdalyanda/cipher-weave 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/ */

    

burakdalyanda / cipher-weave example snippets


->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'encrypt.request.response' => \BurakDalyanda\CipherWeave\Middleware\EncryptRequestResponse::class,
    ]);
})

protected $routeMiddleware = [
    // Other middleware
    'encrypt.request.response' => \BurakDalyanda\CipherWeave\Middleware\EncryptRequestResponse::class,
];

Route::middleware(['encrypt.request.response'])->group(function () {
    Route::get('/secure-endpoint', [SecureController::class, 'index']);
});

Route::middleware(['encrypt.request.response:your-custom-base64-key'])->group(function () {
    Route::get('/secure-endpoint', [SecureController::class, 'index']);
});

use BurakDalyanda\CipherWeave\Facades\CipherWeave;

$encrypted = CipherWeave::encrypt('secret message');
$decrypted = CipherWeave::decrypt($encrypted);

use BurakDalyanda\CipherWeave\Contracts\CipherWeaveInterface;

public function __construct(private CipherWeaveInterface $cipher) {}

public function someMethod() {
    $encrypted = $this->cipher->encrypt(['data' => 'to encrypt']);
}
bash
php artisan vendor:publish --tag=cipherweave-config
bash
php artisan cipherweave:key