Skip to content

Latest commit

 

History

History
76 lines (48 loc) · 1.67 KB

README.md

File metadata and controls

76 lines (48 loc) · 1.67 KB

PHP Encryption Library

A secure and efficient PHP library for encrypting and decrypting data using AES-256-GCM.

Features

  • 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.

Installation

1. Clone the Repository

git clone https://github.com/caferkara/php-encryption-library.git
cd php-encryption-library

2. Set Up Dependencies

Ensure you have PHP installed and the openssl extension enabled.

3. Configure Environment Variables

  1. Rename the .env.example file to .env.
  2. 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.

Usage

Encrypting Data

require 'Encryption.php';

$encryption = new Encryption();

$data = "Sensitive information";
$encryptedData = $encryption->encrypt($data);

echo "Encrypted: " . $encryptedData;

Decrypting Data

$decryptedData = $encryption->decrypt($encryptedData);

echo "Decrypted: " . $decryptedData;

Security Best Practices

  • Use a strong, unique ENCRYPTION_KEY and PEPPER for each project.
  • Never expose your .env file publicly.
  • Regularly rotate keys and update environment variables.

Output Example

Encrypted Data: GksD8ks83NLVm29NN3U8Z24wQfJHQH6lQKw+....(truncated)
Decrypted Data: Hello, World!

Requirements

  • PHP 7.4 or higher.
  • OpenSSL extension enabled.

License

This project is licensed under the MIT License.