PHP code example of rnr1721 / le7-cryptography

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

    

rnr1721 / le7-cryptography example snippets


// Include the Cryptography class
use rnr1721\Core\Cryptography;

// Initialize Cryptography with a key and method (optional)
$crypto = new Cryptography('your_secret_key', 'AES-256-CBC');

// Encrypt a password
$encryptedPassword = $crypto->encryptPassword('my_password');

// Decrypt an encrypted password
$decryptedPassword = $crypto->decryptPassword($encryptedPassword);

// Generate a random password
$randomPassword = $crypto->generateRandomPassword();

// Verify a password against its encrypted counterpart
$isPasswordValid = $crypto->verifyPassword('my_password', $encryptedPassword);

// Include the Cryptography class
use rnr1721\Core\Cryptography;

// Initialize Cryptography with a key and method (optional)
$crypto = new Cryptography();

// Encrypt a password
$encryptedPassword = $crypto->encryptPassword('my_password','your_secret_key','AES-256-CBC');

// Decrypt an encrypted password
$decryptedPassword = $crypto->decryptPassword($encryptedPassword,'your_secret_key','AES-256-CBC');

// Generate a random password. Length is optional, default is 7
$randomPassword = $crypto->generateRandomPassword(7);

// Verify a password against its encrypted counterpart
$isPasswordValid = $crypto->verifyPassword('my_password', $encryptedPassword,'your_secret_key','AES-256-CBC');

// Include the Cryptography class
use rnr1721\Core\Cryptography;

// Initialize Cryptography with a key and method (optional)
$crypto = new Cryptography('your_secret_key', 'AES-256-CBC');

$crypto->setDefaultPasswordChars('abcdefgh');

$newPassword = $crypto->generateRandomPassword(5);


// Include the Cryptography class
use rnr1721\Core\Cryptography;
$crypto = new Cryptography('your_secret_key', 'AES-256-CBC');
$allowedMethods = $crypto->getAllowedMethods();