Temant Encryption Manager is a simple and secure encryption library for PHP. It provides an easy-to-use API for encrypting and decrypting strings and files using AES-128-CBC and AES-256-CBC encryption algorithms.
You can install the library using Composer:
composer require temant/encryption-manager
To encrypt a string:
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";
To encrypt a string with a password:
$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";
To encrypt and decrypt files:
// 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";
To run the tests, use the following command:
vendor/bin/phpunit
This project is licensed under the BSD 3-Clause License License.