A secure and efficient PHP library for encrypting and decrypting data using AES-256-GCM.
- Uses AES-256-GCM encryption for maximum security.
- Includes random IVs and salts for each operation.
- Utilizes environment variables for key management.
- Supports HMAC-based key derivation.
git clone https://github.com/caferkara/php-encryption-library.git
cd php-encryption-library
Ensure you have PHP installed and the openssl extension enabled.
- Rename the .env.example file to .env.
- Add your own secure values for ENCRYPTION_KEY and PEPPER:
ENCRYPTION_KEY=fX9&c3@8kLp#5ZqT7v$W!yR2N%hQ8m
PEPPER=G7s@1Lp!d4$kH9#y
Important
Use a strong, random value for both keys. Never share or expose these keys.
require 'Encryption.php';
$encryption = new Encryption();
$data = "Sensitive information";
$encryptedData = $encryption->encrypt($data);
echo "Encrypted: " . $encryptedData;
$decryptedData = $encryption->decrypt($encryptedData);
echo "Decrypted: " . $decryptedData;
- Use a strong, unique ENCRYPTION_KEY and PEPPER for each project.
- Never expose your .env file publicly.
- Regularly rotate keys and update environment variables.
Encrypted Data: GksD8ks83NLVm29NN3U8Z24wQfJHQH6lQKw+....(truncated)
Decrypted Data: Hello, World!
- PHP 7.4 or higher.
- OpenSSL extension enabled.
This project is licensed under the MIT License.