PHPackages                             davodm/dgcrypt-php - 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. davodm/dgcrypt-php

ActiveLibrary[Security](/categories/security)

davodm/dgcrypt-php
==================

A simple PHP library for encryption and decryption using AES-256-CBC to be usable in different language/devices.

v0.0.2(2y ago)19PHPPHP &gt;=8.2

Since Jul 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/davodm/dgcrypt-php)[ Packagist](https://packagist.org/packages/davodm/dgcrypt-php)[ RSS](/packages/davodm-dgcrypt-php/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

Dgcrypt
=======

[](#dgcrypt)

Dgcrypt is a simple PHP library for encryption and decryption using multiple encryption methods including **AES-256-CBC**, **AES-256-GCM**, and **ChaCha20-Poly1305**. It is designed to securely encrypt data on the backend, which can then be easily decrypted on the client side, such as on Android and iOS devices. This ensures that the data remains secure during transmission and cannot be easily cracked in between.

Platform Compatibility
----------------------

[](#platform-compatibility)

The Dgcrypt library is designed to work seamlessly across multiple platforms. You can find corresponding libraries for the following platforms:

- **Android**: [Dgcrypt-Android](https://github.com/davodm/dgcrypt-android)
- **Node.js**: [Dgcrypt-Node](https://github.com/davodm/dgcrypt-node)

These libraries allow you to easily decrypt data that was encrypted on the backend using this PHP library, ensuring secure communication between your backend and client applications.

Supported Encryption Methods
----------------------------

[](#supported-encryption-methods)

Dgcrypt supports the following encryption methods:

- **AES-256-CBC**: Standard encryption method providing confidentiality.
- **AES-256-GCM**: Provides both encryption and authentication.
- **ChaCha20-Poly1305**: Modern encryption method known for its performance and security.

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

[](#installation)

You can install the package via Composer:

```
composer require davodm/dgcrypt-php
```

Usage
-----

[](#usage)

### Setting Up

[](#setting-up)

```
use Dgcrypt\Dgcrypt;

// Initialize the Dgcrypt class with the desired encryption method
$dgcrypt = new Dgcrypt('aes-256-gcm'); // Can be 'aes-256-cbc', 'aes-256-gcm', or 'chacha20-poly1305'

// Set a secret key
$dgcrypt->setKey('your-secret key');
```

### Encrypting Data on the Backend:

[](#encrypting-data-on-the-backend)

```
// Encrypt a string
$plainText = 'Hello, World!';
$encrypted = $dgcrypt->encrypt($plainText);

// Output the encrypted string
echo $encrypted;
```

### Decrypting Data on the Backend:

[](#decrypting-data-on-the-backend)

```
// Decrypt the previously encrypted string
$decrypted = $dgcrypt->setCipherMethod('aes-256-cbc')->decrypt($encrypted);

// Output the decrypted string
echo $decrypted;
```

### Auto-Generating a Key:

[](#auto-generating-a-key)

```
// Generate a secure random key
$generatedKey = $dgcrypt->generateKey();

// Output the generated key
echo $generatedKey; // Display the hexadecimal key
```

### Setting the Initialization Vector (IV):

[](#setting-the-initialization-vector-iv)

```
// Optionally, set a custom IV (12 bytes for GCM or ChaCha20, 16 bytes for CBC)
// If no IV is set, a secure random IV will be generated automatically
$dgcrypt->setIV();
```

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.

Author
------

[](#author)

Davod Mozafari - [Twitter](https://twitter.com/davodmozafari)

###  Health Score

21

—

LowBetter than 17% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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 ~10 days

Total

2

Last Release

744d ago

PHP version history (2 changes)v0.0.1PHP &gt;=7.1

v0.0.2PHP &gt;=8.2

### Community

Maintainers

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

---

Top Contributors

[![davodm](https://avatars.githubusercontent.com/u/10187129?v=4)](https://github.com/davodm "davodm (11 commits)")

---

Tags

aeschacha20encryptionphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/davodm-dgcrypt-php/health.svg)

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

###  Alternatives

[phpids/phpids

PHPIDS (PHP-Intrusion Detection System) is a simple to use, well structured, fast and state-of-the-art security layer for your PHP based web application

791150.0k2](/packages/phpids-phpids)[paragonie/ecc

PHP Elliptic Curve Cryptography library

25866.3k44](/packages/paragonie-ecc)[sansec/magento2-module-shield

15218.6k](/packages/sansec-magento2-module-shield)[nicobleiler/php-passphrase

Passphrase generator with Laravel integration, inspired by Bitwarden. Uses the EFF long word list by default with support for custom wordlists.

4912.6k](/packages/nicobleiler-php-passphrase)[dwgebler/encryption

Encryption wrapper for PHP using libsodium — simple API for symmetric and asymmetric encryption, password hashing, digital signing, and message authentication.

317.5k](/packages/dwgebler-encryption)

PHPackages © 2026

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