PHP code example of initphp / encryption

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

    

initphp / encryption example snippets

 
$options = [
    'algo'      => 'SHA256',
    'cipher'    => 'AES-256-CTR',
    'key'       => null,
    'blocksize' => 16,
];
 
use \InitPHP\Encryption\Encrypt;

// OpenSSL Handler
/** @var $openssl \InitPHP\Encryption\HandlerInterface */
$openssl = Encrypt::use(\InitPHP\Encryption\OpenSSL::class, [
    'algo'      => 'SHA256',
    'cipher'    => 'AES-256-CTR',
    'key'       => 'TOP_Secret_Key',
]);

// Sodium Handler
/** @var $sodium \InitPHP\Encryption\HandlerInterface */
$sodium = Encrypt::use(\InitPHP\Encryption\Sodium::class, [
    'key'       => 'TOP_Secret_Key',
    'blocksize' => 16,
]);
 
public function encrypt(mixed $data, array $options = []): string;
 
public function decrypt(string $data, array $options = []): mixed;
 
namespace App;

use \InitPHP\Encryption\{HandlerInterface, BaseHandler};

class MyHandler extends BaseHandler implements HandlerInterface
{
    public function encrypt($data, array $options = []): string
    {
        $options = $this->options($options);
        // ... process
    }

    public function decrypt($data, array $options = [])
    {
        $options = $this->options($options);
        // ... process
    }
}
 
use \InitPHP\Encryption\Encrypt;

$myhandler = Encrypt::use(\App\MyHandler::class);