PHPackages                             robertogriel/crypt-array - 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. robertogriel/crypt-array

ActiveLibrary[Security](/categories/security)

robertogriel/crypt-array
========================

A simple PHP library to encrypt and decrypt strings or associative arrays using OpenSSL.

2.0.0(1y ago)115MITPHPPHP &gt;=8.0CI passing

Since May 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/robertogriel/crypt-array)[ Packagist](https://packagist.org/packages/robertogriel/crypt-array)[ RSS](/packages/robertogriel-crypt-array/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

🔐 Crypt Array
=============

[](#-crypt-array)

Encrypt or decrypt **strings** and **associative arrays** in PHP using OpenSSL and AES-128-CBC.

> ✅ Compatible with **PHP 8.2+**

---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require robertogriel/crypt-array
```

---

🚀 Usage
-------

[](#-usage)

### 1. Create a Crypto instance

[](#1-create-a-crypto-instance)

```
use Crypto\Crypto;

$crypto = new Crypto('YOUR_SECRET_KEY', 'YOUR_SECRET_IV', true); // true = use Base64
```

---

### 2. Encrypting an array

[](#2-encrypting-an-array)

```
$data = [
    'username' => 'john',
    'email'    => 'john@example.com'
];

$encrypted = $crypto->encrypt($data);
```

---

### 3. Decrypting an array

[](#3-decrypting-an-array)

```
$decrypted = $crypto->decrypt($encrypted);
```

---

### 4. Encrypting a string

[](#4-encrypting-a-string)

```
$encrypted = $crypto->encrypt('Hello world');
```

---

### 5. Decrypting a string

[](#5-decrypting-a-string)

```
$decrypted = $crypto->decrypt($encrypted);
```

---

⚙️ Options
----------

[](#️-options)

The third parameter of the constructor is a boolean to enable **Base64 encoding**:

```
$crypto = new Crypto('key', 'iv', true); // true = enable Base64
```

---

📁 Full Example
--------------

[](#-full-example)

See the full example file: [`sample.php`](sample.php)

It includes:

- Input data
- Encrypted values
- Decrypted results
- Code snippets used

---

🧯 Migration Guide (v1.x → v2.x)
-------------------------------

[](#-migration-guide-v1x--v2x)

Previous versions used `getEncrypted()` and `getDecrypted()` and required a second argument to indicate a string.

### 🔄 Old usage:

[](#-old-usage)

```
$crypto->getEncrypted('string', 1);
$crypto->getDecrypted('string', 1);
```

### ✅ Now:

[](#-now)

```
$crypto->encrypt('string');
$crypto->decrypt('string');
```

The methods are now smart enough to detect whether you're using a string or an array.

---

✅ Requirements
--------------

[](#-requirements)

- PHP &gt;= 8.2
- OpenSSL extension enabled

---

🧪 Testing
---------

[](#-testing)

Run the full test suite with [Pest](https://pestphp.com):

```
./vendor/bin/pest
```

---

📘 License
---------

[](#-license)

MIT © [robertogriel](mailto:roberto@griel.com.br)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance46

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Every ~347 days

Total

4

Last Release

415d ago

Major Versions

0.1 → 1.02022-05-21

1.1 → 2.0.02025-03-29

PHP version history (2 changes)0.1PHP &gt;=5.6.0

2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/752608157e84eb8f01ccef5b01f30bce5d55cee9d473634501c3c9169b072d7a?d=identicon)[robertogriel](/maintainers/robertogriel)

---

Top Contributors

[![robertogriel](https://avatars.githubusercontent.com/u/40149977?v=4)](https://github.com/robertogriel "robertogriel (35 commits)")

---

Tags

arraydecryptencryptopensslphp

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/robertogriel-crypt-array/health.svg)

```
[![Health](https://phpackages.com/badges/robertogriel-crypt-array/health.svg)](https://phpackages.com/packages/robertogriel-crypt-array)
```

###  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)
