PHPackages                             rkeet/zf-doctrine-encrypt - 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. rkeet/zf-doctrine-encrypt

Abandoned → [somecoding/laminas-doctrine-encrypt](/?search=somecoding%2Flaminas-doctrine-encrypt)ArchivedLibrary[Security](/categories/security)

rkeet/zf-doctrine-encrypt
=========================

Provides property encryption and hashing for Doctrine Entities when used within Zend Framework 3.

1.1.3(6y ago)62.7k12MITPHPPHP ^7.2 || ^7.3

Since Dec 15Pushed 6y ago2 watchersCompare

[ Source](https://github.com/rkeet/zf-doctrine-encrypt)[ Packagist](https://packagist.org/packages/rkeet/zf-doctrine-encrypt)[ Docs](https://keet.me/)[ RSS](/packages/rkeet-zf-doctrine-encrypt/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (7)Used By (0)

Zend Framework 3 &amp; Doctrine Encrypt Module
==============================================

[](#zend-framework-3--doctrine-encrypt-module)

Provides a Zend Framework 3 &amp; Doctrine 2 encryption module.

Installation
============

[](#installation)

```
composer require rkeet/zf-doctrine-encrypt

```

Requirements
============

[](#requirements)

- PHP 7.2 or greater (must have Sodium extension enabled)

If you're on Windows, using Xampp, the PHP 7.2 installation might not automatically enable the Sodium extension. If this the case, you'll get an error (`'This is not implemented, as it is not possible to securely wipe memory from PHP'`). Enable Sodium for PHP by adding this to your `php.ini` file:

```
extension = C:\xampp\php\ext\php_sodium.dll

```

This might also be applicable ot other local installations.

Configuration
=============

[](#configuration)

Zend Framework
--------------

[](#zend-framework)

Make sure to add the module to you application configuration. In your `modules.config.php` make sure to include `Keet\\Encrypt`.

### Additional

[](#additional)

The configuration which is used makes use of aliases, such as `hashing_service` and `encryption_adapter`. You may override these with your own config to implement your own Service and/or Adapter classes. These will automatically be used by this module if the correct Interface classes are implemented. Make sure to read through the code before you do any of this though.

Module
------

[](#module)

`*.dist` files are provided. Copy these (remove extension) to your application and fill in the required key/salt values. If these are filled in, it works out of the box using [Halite](https://github.com/paragonie/halite) for encryption.

However, must be said, at the moment of writing this ReadMe, the Halite module contains duplicate `const` declarations, as such, you must disable your `E_NOTICE` warnings in your PHP config :(

Annotation Examples
-------------------

[](#annotation-examples)

### Encryption

[](#encryption)

Simple, consider that you have an `Address` Entity, which under the [EU GDPR regulation](https://www.eugdpr.org/)requires parts of the address, such as the street, to be encrypted. This uses the key &amp; salt required for the config by default

To encrypt a street name, add `@Encrypted` like so:

```
/**
 * @var string
 * @ORM\Column(name="street", type="text", nullable=true)
 * @Encrypted
 */
protected $street;

```

By default the Encryption service assumes that the data to be encrypted is of the type `string`. However, you could have a requirement to encrypt another type of data, such as a house number. Non-string types are supported, but the type of data must be provided if not a string. You can do this like so:

```
/**
 * @var int
 * @ORM\Column(name="house_number", type="text", nullable=false)
 * @Encrypted(type="int")
 */
protected $houseNumber;

```

Supported types are [found here](http://php.net/settype).

### Cyphertext representation

[](#cyphertext-representation)

The cypher text always results in a string with varying length always longer than 255 chars. Therefore you should use a datatype capable of representing the full length of it. Be aware that any non-string property will be handled as a string representation in the database.

### Hashing

[](#hashing)

Say you'd like to store a password, it should work in much of the same way as the above. However, it is data that should not be de-cryptable (and there's no need for it to ever be decrypted), thus you should hash it instead.

To hash something, like a password, add the `@Hashed` Annotation. See the example below.

```
/**
 * @var string
 * @ORM\Column(name="password", type="text", nullable=false)
 * @Hashed
 */
protected $password;

```

**Note** that, unlike `@Encrypted`, there aren't options to give a type. As we can't decrypt the data (it's one-way), there's no need to know what the original type was. The response will always be string value.

Controller Examples
-------------------

[](#controller-examples)

### Hashing

[](#hashing-1)

A `HashingService` is provided. This service also uses the `HashingAdapter` but provides functionality that can be used in Controllers and other classes, such as plugins. The service is registered under the alias 'hashing\_service'. You can override 'hasing\_service' in your own project to provide your own implementation.

The `HashingService` provides the ability to hash and verify strings. These are two separate operations, one one-way hashes a string. The other does the same (requires the hashed string) and then verifies that both strings are exactly the same (thus verifying).

In a Controller, to hash a string, simply do:

```
$secret = $this->getHashingService()->hash('correct horse battery staple');

```

To verify that your dealing the same string a next time, for example to compare passwords on login, do:

```
$verified = $this->getHashingService()->verify('correct horse battery staple', $secret);

```

`$verified` will be set to a boolean value.

To not store any entered data longer than you must, you could compare directly from form data, like so:

```
if($form->isValid() && $this->getHashingService()->verify($form->getData()['password_field'], $user->getPassword()) {
    // do other things
}

```

### Encryption

[](#encryption-1)

An `EncryptionService` is also provided and works in much the same way as the `HashingService`. It provides functionality to encrypt and to decrypt data.

To encrypt data, do:

```
$encrypted = $this->getEncryptionService()->encrypt('correct horse battery staple');

```

To decrypt data, do:

```
$decrypted = $this->getEncryptionService()->decrypt($string);

```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 76.9% 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 ~116 days

Total

5

Last Release

2239d ago

PHP version history (2 changes)1.0.0PHP ^7.2

1.1PHP ^7.2 || ^7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/374f905cbf90dd014abeee57b1d7ebda40f3bd9c4fca88091607e75b5033e6ea?d=identicon)[rkeet](/maintainers/rkeet)

---

Top Contributors

[![rkeet](https://avatars.githubusercontent.com/u/3327864?v=4)](https://github.com/rkeet "rkeet (10 commits)")[![Dwarfex](https://avatars.githubusercontent.com/u/721721?v=4)](https://github.com/Dwarfex "Dwarfex (3 commits)")

---

Tags

doctrine-ormdoctrine2encryptioneventgdprhashingphpphp72sodiumzend-framework3encryptionencryptdoctrine2modulezf3Zend Framework 3

### Embed Badge

![Health badge](/badges/rkeet-zf-doctrine-encrypt/health.svg)

```
[![Health](https://phpackages.com/badges/rkeet-zf-doctrine-encrypt/health.svg)](https://phpackages.com/packages/rkeet-zf-doctrine-encrypt)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[paragonie/ciphersweet

Searchable field-level encryption library for relational databases

4641.2M21](/packages/paragonie-ciphersweet)[sbamtr/laravel-source-encrypter

Laravel Source Encrypter

58545.6k](/packages/sbamtr-laravel-source-encrypter)[nzo/url-encryptor-bundle

The NzoUrlEncryptorBundle is a Symfony Bundle used to Encrypt and Decrypt data and variables in the Web application or passed through URL

961.0M2](/packages/nzo-url-encryptor-bundle)

PHPackages © 2026

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