PHPackages                             initphp/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. initphp/encryption

ActiveLibrary[Security](/categories/security)

initphp/encryption
==================

PHP OpenSSL/Sodium Encryption and Decryption

1.0(4y ago)220822MITPHPPHP &gt;=7.4

Since Mar 15Pushed 4y ago1 watchersCompare

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

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

Encryption
==========

[](#encryption)

PHP OpenSSL/Sodium Encryption and Decryption

[![Latest Stable Version](https://camo.githubusercontent.com/b33c836ee1a976b9688d5b3df21d9957fa012e68114b2ff0380ee64a26182064/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f656e6372797074696f6e2f76)](https://packagist.org/packages/initphp/encryption) [![Total Downloads](https://camo.githubusercontent.com/5809b398009efa55556470886366dfd7307d1a315b2a91d7dae41723d2fdba6c/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f656e6372797074696f6e2f646f776e6c6f616473)](https://packagist.org/packages/initphp/encryption) [![Latest Unstable Version](https://camo.githubusercontent.com/8d4f3620f983a1f86087c9217085465b49ca1371776583011de001df231a3061/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f656e6372797074696f6e2f762f756e737461626c65)](https://packagist.org/packages/initphp/encryption) [![License](https://camo.githubusercontent.com/333a92612217380e26781e2bd182102dde19d339a2fb2339898c32f1706b9544/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f656e6372797074696f6e2f6c6963656e7365)](https://packagist.org/packages/initphp/encryption) [![PHP Version Require](https://camo.githubusercontent.com/5b8b661f22a26c2d47e4314a32c8f7d38bbc70a1610ab0f3548ffe00c7708ee9/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f656e6372797074696f6e2f726571756972652f706870)](https://packagist.org/packages/initphp/encryption)

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- MB\_String extension
- Depending on usage:
    - OpenSSL extesion
    - Sodium extension

Installation
------------

[](#installation)

```
composer require initphp/encryption

```

Configuration
-------------

[](#configuration)

```
$options = [
    'algo'      => 'SHA256',
    'cipher'    => 'AES-256-CTR',
    'key'       => null,
    'blocksize' => 16,
];
```

- `algo` : Used by OpenSSL handler only. The algorithm to use to sign the data.
- `cipher` : Used by OpenSSL handler only. The encryption algorithm that will be used to encrypt the data.
- `key` : The top secret key string to use for encryption.
- `blocksize` : It is used for sodium handler only. It is used in the `sodium_pad()` and `sodium_unpad()` functions.

Usage
-----

[](#usage)

```
require_once "vendor/autoload.php";
use \InitPHP\Encryption\Encrypt;

// OpenSSL Handler
/** @var $openssl \InitPHP\Encryption\HandlerInterface */
$openssl = Encrypt::use(\InitPHP\Encryption\OpenSSL::class, [
    'algo'      => 'SHA256',
    'cipher'    => 'AES-256-CTR',
    'key'       => 'TOP_Secret_Key',
]);

// Sodium Handler
/** @var $sodium \InitPHP\Encryption\HandlerInterface */
$sodium = Encrypt::use(\InitPHP\Encryption\Sodium::class, [
    'key'       => 'TOP_Secret_Key',
    'blocksize' => 16,
]);
```

### Methods

[](#methods)

#### `encrypt()`

[](#encrypt)

```
public function encrypt(mixed $data, array $options = []): string;
```

#### `decrypt()`

[](#decrypt)

```
public function decrypt(string $data, array $options = []): mixed;
```

Writing Your Own Handler
------------------------

[](#writing-your-own-handler)

```
namespace App;

use \InitPHP\Encryption\{HandlerInterface, BaseHandler};

class MyHandler extends BaseHandler implements HandlerInterface
{
    public function encrypt($data, array $options = []): string
    {
        $options = $this->options($options);
        // ... process
    }

    public function decrypt($data, array $options = [])
    {
        $options = $this->options($options);
        // ... process
    }
}
```

```
use \InitPHP\Encryption\Encrypt;

$myhandler = Encrypt::use(\App\MyHandler::class);
```

Getting Help
------------

[](#getting-help)

If you have questions, concerns, bug reports, etc, please file an issue in this repository's Issue Tracker.

Getting Involved
----------------

[](#getting-involved)

> All contributions to this project will be published under the MIT License. By submitting a pull request or filing a bug, issue, or feature request, you are agreeing to comply with this waiver of copyright interest.

There are two primary ways to help:

- Using the issue tracker, and
- Changing the code-base.

### Using the issue tracker

[](#using-the-issue-tracker)

Use the issue tracker to suggest feature requests, report bugs, and ask questions. This is also a great way to connect with the developers of the project as well as others who are interested in this solution.

Use the issue tracker to find ways to contribute. Find a bug or a feature, mention in the issue that you will take on that effort, then follow the Changing the code-base guidance below.

### Changing the code-base

[](#changing-the-code-base)

Generally speaking, you should fork this repository, make changes in your own fork, and then submit a pull request. All new code should have associated unit tests that validate implemented features and the presence or lack of defects. Additionally, the code should follow any stylistic and architectural guidelines prescribed by the project. In the absence of such guidelines, mimic the styles and patterns in the existing code-base.

Credits
-------

[](#credits)

- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr)

License
-------

[](#license)

Copyright © 2022 [MIT License](./LICENSE)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

1524d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b6b34f3ac8938d8ee52ba3bd260680855dc5715c7b2929d9380de30d15a67dd?d=identicon)[muhammetsafak](/maintainers/muhammetsafak)

---

Top Contributors

[![muhammetsafak](https://avatars.githubusercontent.com/u/104234499?v=4)](https://github.com/muhammetsafak "muhammetsafak (1 commits)")

---

Tags

encryptionencryption-decryptionopensslopenssl-libraryphpphp-encryptionphp-opensslphp-sodiumphp7sodiumsodium-library

### Embed Badge

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

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

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/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.7M113](/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)
