PHPackages                             ericledberg/php-encryption - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. ericledberg/php-encryption

ActiveLibrary[Security](/categories/security)

ericledberg/php-encryption
==========================

A PHP class that provides encryption functionality using OpenSSL AES CBC encryption

v0.2alpha(2y ago)04MITPHPPHP &gt;=7.2.0

Since May 2Pushed 2y ago1 watchersCompare

[ Source](https://github.com/EricLEdberg/PHP-Encryption)[ Packagist](https://packagist.org/packages/ericledberg/php-encryption)[ RSS](/packages/ericledberg-php-encryption/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP-Encryption - A PHP Class for Encryption and Decryption
==========================================================

[](#php-encryption---a-php-class-for-encryption-and-decryption)

PHP-Encryption is a class that provides SYMETRIC encryption and decryption functionality using the OpenSSL library. It uses the Advanced Encryption Standard (AES) algorithm in Cipher-Block Chaining (CBC) mode for secure data encryption.

Remember, keeping encryption keys secure and private are essential to maintaining data security. This excescise is left to the user application.

#### Features

[](#features)

- Ability to import encryption keys from a secured ".env" file or set by the application at run-time
- Strong encryption of the data using AES-256-CBC cipher
- Optionally calculate HMAC\_HASH on originally-encrypted data
- Optionally combines the encrypted data and it's HMAC\_HASH and encrypts it a second time sing KEY2
- Optionally will compare the originally encrypted data to it's HMAC\_HASH to verify it was not tampered with

#### Installation

[](#installation)

Install PHP-Encryption via Composer using the following command:

`composer require ericledberg/PHP-Encryption`

Alternatively, you can manually download and include the cksEncryption.php file in your PHP project.

Optionally, initialize .ENV keyfile:

- Locate Example.env in: Composer/vendor/php-encryption
- Copy example to: cp Example.env .env
- For production, generate new keys and update .env
- Update .env permissions to limit access
    - sudo chown root .env
    - sudo chgrp apache2 .env
    - sudo chmod 440 .env

Example: Composer Using .ENV To Store Keys
==========================================

[](#example--composer-using-env-to-store-keys)

Here's an example of how to use PHP-Encryption in your PHP code using composer.

ericledberg/php-encryption

```
// Alter path to where test.php script resides
$autoloader = require __DIR__ . '/vendor/autoload.php';

$aOptions = array();
$aOptions['ENVKEYFILE'] = __DIR__ . "/.env";

$objENC = new \clsEncryption\clsEncryption($aOptions);
echo "objENC() created";

// Encrypt data
$data = 'Hello, world!';
$encryptedData = $objENC->encrypt($data);

// Decrypt data
$decryptedData = $objENC->decrypt($encryptedData);

// Display results
echo "Original data: $data\n";
echo "Encrypted data: $encryptedData\n";
echo "Decrypted data: $decryptedData\n";
```

Example: Simple Require Class
=============================

[](#example--simple-require-class)

```
// --------------------------------------------
// encryption
// APP does not have knowledge about about internal operations of clsEncryption, including keys
// --------------------------------------------
$aOptions = array();
$aOptions['ENVKEYFILE'] = __DIR__ . $config['folderSep'] . ".envENCRYPTION";
require_once('./clsEncryption.php');
$objENC = new \clsEncryption\clsEncryption($aOptions);

// Optionally execute built-in tests...
//$objENC->ExecuteTests();
//exit;

// Encrypt data
$data = 'Hello, world!';
$encryptedData = $objENC->encrypt($data);

// Decrypt data
$decryptedData = $objENC->decrypt($encryptedData);

// Display results
echo "Original data: $data\n";
echo "Encrypted data: $encryptedData\n";
echo "Decrypted data: $decryptedData\n";
```

Security Considerations
-----------------------

[](#security-considerations)

- Properly manage encryption keys and keep them confidential and protected from unauthorized access.
- Store encrypted data and encryption keys securely with appropriate access controls.
- Validate and sanitize input data to prevent potential security vulnerabilities.
- Regularly audit and review the implementation for security risks.
- Ensure compliance with applicable data protection laws and industry regulations, especially when handling sensitive data.

Contribution
------------

[](#contribution)

Contributions to PHP-Encryption are welcome! Please submit issues and pull requests to the GitHub repository at .

License
-------

[](#license)

PHP-Encryption is released under the MIT License, which allows for both personal and commercial use. Please see the LICENSE file for more details.

Credits
-------

[](#credits)

PHP-Encryption was created by [ericledberg](https://github.com/ericledberg) and is inspired by various PHP encryption libraries and best practices for encryption and key management.

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

746d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/127bcdffe2e803b71251f515f50f3b5645fc97b1a58e63f04d029d091bff3b57?d=identicon)[EricLEdberg](/maintainers/EricLEdberg)

---

Top Contributors

[![EricLEdberg](https://avatars.githubusercontent.com/u/8417082?v=4)](https://github.com/EricLEdberg "EricLEdberg (12 commits)")

---

Tags

phpencryptionaes

### Embed Badge

![Health badge](/badges/ericledberg-php-encryption/health.svg)

```
[![Health](https://phpackages.com/badges/ericledberg-php-encryption/health.svg)](https://phpackages.com/packages/ericledberg-php-encryption)
```

###  Alternatives

[brainfoolong/js-aes-php

Slim native AES encryption/decryption on client side with Javascript and on server side with PHP

1311.8k](/packages/brainfoolong-js-aes-php)[poly-crypto/poly-crypto

High-level cryptographic functions that are interoperable between NodeJS and PHP 7.1+

127.8k1](/packages/poly-crypto-poly-crypto)[stymiee/php-simple-encryption

The PHP Simple Encryption library is designed to simplify the process of encrypting and decrypting data while ensuring best practices are followed. By default is uses a secure encryption algorithm and generates a cryptologically strong initialization vector so developers do not need to becomes experts in encryption to securely store sensitive data.

448.0k](/packages/stymiee-php-simple-encryption)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
