PHP code example of slam / php-symmetric-encryption
1. Go to this page and download the library: Download slam/php-symmetric-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/ */
slam / php-symmetric-encryption example snippets
use SlamSymmetricEncryption\V1Encryptor;
// Generate a key and save it somewhere
$key = V1Encryptor::generateKey();
var_dump($key); // string(44) "Hog2u9jtOzyt+mPyAJwp8v3dI6Uvp1T4FUKrAjizVGo="
// Use the key
$encryptor = new V1Encryptor($key);
$ciphertext = $encryptor->encrypt('foo');
var_dump($ciphertext); // string(59) "dznmjbqHnI_26crKpRYvp125K9N6ctqU0kVCmoSRbG7HAKCIrnAz0RBELQ"
$plaintext = $encryptor->decrypt($ciphertext);
var_dump($plaintext); // string(3) "foo"