PHP code example of temant / encryption-manager

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

    

temant / encryption-manager example snippets


use Temant\EncryptionManager\EncryptionManager;
use Temant\EncryptionManager\EncryptionTypeEnum;

// Initialize the Encryption class with a key
$encryption = new EncryptionManager('your-encryption-key', EncryptionTypeEnum::BYTES_256);

// Encrypt a string
$plainText = 'Hello, World!';
$encrypted = $encryption->encryptString($plainText);

// Decrypt the string
$decrypted = $encryption->decryptString($encrypted);

echo "Encrypted: $encrypted\n";
echo "Decrypted: $decrypted\n";

$plainText = 'Sensitive Data';
$password = 'your-secure-password';

$encrypted = $encryption->encryptString($plainText, $password);
$decrypted = $encryption->decryptString($encrypted, $password);

echo "Encrypted: $encrypted\n";
echo "Decrypted: $decrypted\n";

// Encrypt a file
$inputFile = 'path/to/input/file.txt';
$encryptedFile = 'path/to/encrypted/file.txt';
$password = 'file-password';

$encryption->encryptFile($inputFile, $encryptedFile, $password);

// Decrypt the file
$decryptedFile = 'path/to/decrypted/file.txt';
$encryption->decryptFile($encryptedFile, $decryptedFile, $password);

$decryptedContent = file_get_contents($decryptedFile);
echo "Decrypted file content: $decryptedContent\n";