Skip to content

A lightweight and secure PHP library for encrypting and decrypting sensitive data using AES-256-GCM. Features include random IVs, salts, and HMAC-based key derivation for maximum security. Easy to integrate and configure with environment variables.

License

Notifications You must be signed in to change notification settings

caferkara/PHP-Encryption-Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

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.

About

A lightweight and secure PHP library for encrypting and decrypting sensitive data using AES-256-GCM. Features include random IVs, salts, and HMAC-based key derivation for maximum security. Easy to integrate and configure with environment variables.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages