PHPackages                             iamjohndev/phpencryption - 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. iamjohndev/phpencryption

ActiveLibrary[Security](/categories/security)

iamjohndev/phpencryption
========================

PHPSecryption is a PHP class that provides 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.

661PHP

Since Apr 22Pushed 3y ago1 watchersCompare

[ Source](https://github.com/PseudoDevs/PHPSecryption)[ Packagist](https://packagist.org/packages/iamjohndev/phpencryption)[ RSS](/packages/iamjohndev-phpencryption/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

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

PHPSecryption is a PHP class that provides 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.

#### Features

[](#features)

- Strong encryption using AES-256-CBC cipher.
- Supports custom encryption and decryption keys.
- Error handling for key mismatches and invalid encrypted data.
- Simple and easy-to-use API.

#### Installation

[](#installation)

You can install PHPSecryption via Composer using the following command:

`composer require iamjohndev/phpencryption:dev-main`

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

Usage
=====

[](#usage)

Here's an example of how to use PHPSecryption in your PHP code:

```
require 'vendor/autoload.php'; // Add this line if you're using core PHP

use iamjohndev\PHPSecryption;

// Instantiate PHPSecryption with encryption key
$encryptionKey = 'mysecretencryptionkey';
$phpEncryption = new PHPSecryption($encryptionKey);

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

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

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

You can also set a custom decryption key using the setDecryptionKey() method if you want to use a different key for decryption than the one used for encryption.

```
// Set custom decryption key
$decryptionKey = 'mysecretdecryptionkey';
$phpEncryption->setDecryptionKey($decryptionKey);
```

Error Handling
==============

[](#error-handling)

PHPSecryption provides error handling for key mismatches and invalid encrypted data. If the decryption key does not match the encryption key used, or if the encrypted data is invalid, an exception will be thrown with an appropriate error message.

```
try {
    // Decrypt data with incorrect key
    $invalidDecryptionKey = 'incorrectdecryptionkey';
    $decryptedData = $phpEncryption->decrypt($encryptedData, $invalidDecryptionKey);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\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 PHPSecryption are welcome! Please submit issues and pull requests to the GitHub repository at .

License
-------

[](#license)

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

Credits
-------

[](#credits)

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

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ac66619338aacab90850c8110820e48f5f9d52b917bf7eb317b4e15e63ef8cbc?d=identicon)[PseudoDevs](/maintainers/PseudoDevs)

---

Top Contributors

[![PseudoDevs](https://avatars.githubusercontent.com/u/28098260?v=4)](https://github.com/PseudoDevs "PseudoDevs (5 commits)")

### Embed Badge

![Health badge](/badges/iamjohndev-phpencryption/health.svg)

```
[![Health](https://phpackages.com/badges/iamjohndev-phpencryption/health.svg)](https://phpackages.com/packages/iamjohndev-phpencryption)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M212](/packages/defuse-php-encryption)[roave/security-advisories

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

2.9k97.3M6.4k](/packages/roave-security-advisories)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M112](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41278.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)

PHPackages © 2026

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