PHP code example of kishor-rajbanshi / php-crypt

1. Go to this page and download the library: Download kishor-rajbanshi/php-crypt 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/ */

    

kishor-rajbanshi / php-crypt example snippets


use KishorRajbanshi\Crypt\Crypter;

$key = Crypter::generateKey('AES-256-CBC');

use KishorRajbanshi\Crypt\Crypter;

$key = random_bytes(32); // 32 bytes for AES-256-CBC
$crypter = new Crypter($key, 'AES-256-CBC');

$data = ['name' => 'Kishor', 'role' => 'Developer'];

$encrypted = $crypter->encrypt($data);

$decrypted = $crypter->decrypt($encrypted);

print_r($decrypted);

$encrypted = $crypter->encryptString('Hello World');

$decrypted = $crypter->decryptString($encrypted);

use KishorRajbanshi\Crypt\Exceptions\Decrypt;
use KishorRajbanshi\Crypt\Exceptions\Encrypt;

try {
    $encrypted = $crypter->encrypt('Secret');
} catch (Encrypt $e) {
    echo "Encryption failed: " . $e->getMessage();
}

try {
    $decrypted = $crypter->decrypt($encrypted);
} catch (Decrypt $e) {
    echo "Decryption failed: " . $e->getMessage();
}

RuntimeException
bash
composer