PHPackages                             hamichen/laminas-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. hamichen/laminas-doctrine-encrypt

ActiveLibrary[Security](/categories/security)

hamichen/laminas-doctrine-encrypt
=================================

Provides property encryption and hashing for Doctrine Entities when used within Laminas

1.0.4(1y ago)0529↓100%MITPHPPHP  ~7.2 || 8.0.\* || 8.1.\* || 8.2.\* || 8.3.\*

Since Sep 13Pushed 1y agoCompare

[ Source](https://github.com/hamichen/laminas-doctrine-encrypt)[ Packagist](https://packagist.org/packages/hamichen/laminas-doctrine-encrypt)[ Docs](https://keet.me/)[ RSS](/packages/hamichen-laminas-doctrine-encrypt/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (9)Versions (5)Used By (0)

Laminas &amp; Doctrine Encrypt Module
=====================================

[](#laminas--doctrine-encrypt-module)

Provides a Laminas &amp; Doctrine 2 encryption module. With support for Mezzio.

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

[](#installation)

```
composer require somecoding/laminas-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 / Laminas
------------------------

[](#zend-framework--laminas)

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 :(

Mezzio
------

[](#mezzio)

When using Mezzio, you will want to add the ConfigProvider to your `config/config.php` file.

```
    \Keet\Encrypt\ConfigProvider::class,

```

When declaring the path to your entities (likely the file with `App\ConfigProvider`), be sure to pass the path(s) as an array.

```
    'my_entity' => [
        'class' => AnnotationDriver::class,
        'cache' => 'array',
        'paths' => [ __DIR__ . '/Entity' ],
    ],

```

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

34

—

LowBetter than 79% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

4

Last Release

649d ago

PHP version history (3 changes)1.0.1PHP  ~7.2 || 8.0.\* || 8.1.\*

1.0.2PHP  ~7.2 || 8.0.\* || 8.1.\* || 8.2.\*

1.0.3PHP  ~7.2 || 8.0.\* || 8.1.\* || 8.2.\* || 8.3.\*

### Community

Maintainers

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

---

Top Contributors

[![Dwarfex](https://avatars.githubusercontent.com/u/721721?v=4)](https://github.com/Dwarfex "Dwarfex (16 commits)")[![rkeet](https://avatars.githubusercontent.com/u/3327864?v=4)](https://github.com/rkeet "rkeet (9 commits)")[![hamichen](https://avatars.githubusercontent.com/u/2081191?v=4)](https://github.com/hamichen "hamichen (8 commits)")[![rbroen](https://avatars.githubusercontent.com/u/8131?v=4)](https://github.com/rbroen "rbroen (2 commits)")[![YuraKril](https://avatars.githubusercontent.com/u/4184026?v=4)](https://github.com/YuraKril "YuraKril (1 commits)")[![rvdlee](https://avatars.githubusercontent.com/u/1207082?v=4)](https://github.com/rvdlee "rvdlee (1 commits)")[![tasselchof](https://avatars.githubusercontent.com/u/7921861?v=4)](https://github.com/tasselchof "tasselchof (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

laminasencryptionencryptdoctrine2modulezf3Zend Framework 3

### Embed Badge

![Health badge](/badges/hamichen-laminas-doctrine-encrypt/health.svg)

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

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k158.4M193](/packages/defuse-php-encryption)[doctrine/doctrine-orm-module

Laminas Module that provides Doctrine ORM functionality

4407.2M283](/packages/doctrine-doctrine-orm-module)[doctrine/doctrine-module

Laminas Module that provides Doctrine basic functionality required for ORM and ODM modules

4037.8M110](/packages/doctrine-doctrine-module)[paragonie/ciphersweet

Searchable field-level encryption library for relational databases

4631.2M19](/packages/paragonie-ciphersweet)[doctrine/doctrine-mongo-odm-module

Laminas Module which provides Doctrine MongoDB ODM functionality

86672.2k31](/packages/doctrine-doctrine-mongo-odm-module)[sbamtr/laravel-source-encrypter

Laravel Source Encrypter

58444.8k](/packages/sbamtr-laravel-source-encrypter)

PHPackages © 2026

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