PHP code example of drewlabs / crypt

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

    

drewlabs / crypt example snippets


use Drewlabs\Crypt\Encrypter\Crypt;

// Creates a crypt instance
$instance = Crypt::new();
$encrypted = $instance->encryptString('Raw string value');

use Drewlabs\Crypt\Encrypter\Crypt;

// Creates a crypt instance
$instance = Crypt::new('MySecret');

use Drewlabs\Crypt\Encrypter\Crypt;

// Creates a crypt instance
$instance = Crypt::new(base64_encode('MySecret'));

use Drewlabs\Crypt\Encrypter\Crypt;

// Creates a crypt instance
$instance = Crypt::new();
$encrypted = $instance->encryptString('Raw string value');

// Decrypting text
$plainText = $instance->decryptString($encrypted); // Raw string value

use Drewlabs\Crypt\HMAC\Hash as HMACHash;

$instance = HMACHash::new();
$hash = $instance->make('My Hashable Value');

use Drewlabs\Crypt\HMAC\Hash as HMACHash;

$instance = HMACHash::raw("...."); // Creates a hash instance from a raw sstring composed

use Drewlabs\Crypt\HMAC\Hash as HMACHash;

$hash = HMACHash::new('md5');
// Returns a boolean indicating whether hashed value and plain text matches.
$boolean = $hash::raw("Hashed value")->check('Hello World!');

use Drewlabs\Crypt\Passwords\Factory;

// Creates a hash manager from using argon2i password hasing
$hash = Factory::new()->make(\PASSWORD_ARGON2I)
                ->resolve()
                ->make('SuperSecret');

use function Drewlabs\Crypt\Proxy\usePasswordManager;

// Creates a hash manager from using bcrypt password hasing
$hash = usePasswordManager('bcrypt')->make('SuperSecret');