PHPackages                             paragonie/doctrine-ciphersweet - 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. paragonie/doctrine-ciphersweet

ActiveLibrary[Security](/categories/security)

paragonie/doctrine-ciphersweet
==============================

v0.1.0(7mo ago)14740↓33.3%ISCPHPPHP ^8.2CI passing

Since Oct 1Pushed 7mo agoCompare

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

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

Doctrine-CipherSweet Adapter
============================

[](#doctrine-ciphersweet-adapter)

[![Build Status](https://github.com/paragonie/doctrine-ciphersweet/actions/workflows/ci.yml/badge.svg)](https://github.com/paragonie/doctrine-ciphersweet/actions)[![Example App](https://github.com/paragonie/doctrine-ciphersweet/actions/workflows/example-app.yml/badge.svg)](https://github.com/paragonie/doctrine-ciphersweet/tree/main/docs/example-app)[![Static Analysis](https://github.com/paragonie/doctrine-ciphersweet/actions/workflows/psalm.yml/badge.svg)](https://github.com/paragonie/doctrine-ciphersweet/actions)[![Latest Stable Version](https://camo.githubusercontent.com/3399b17ce4b0d16bbbc973d9726dd28b0d1afa6fd6c25027085670a512a83106/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f646f637472696e652d63697068657273776565742f762f737461626c65)](https://packagist.org/packages/paragonie/doctrine-cipherrsweet)[![Latest Unstable Version](https://camo.githubusercontent.com/cad4b882d9bd3f8ad19ed9728327b72fc25d4c7eade3919e5c581eed3ee9aeb2/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f646f637472696e652d63697068657273776565742f762f756e737461626c65)](https://packagist.org/packages/paragonie/doctrine-cipherrsweet)[![License](https://camo.githubusercontent.com/4170b6cdb57586f5acb6d76f4430ae560fd326658a86c3924e1be5298b24566b/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f646f637472696e652d63697068657273776565742f6c6963656e7365)](https://packagist.org/packages/paragonie/doctrine-ciphersweet)[![Downloads](https://camo.githubusercontent.com/9c22f06b74b2a06fd3cf6404e8f1f215dc226ec8a24b6e828a633bcef17f740c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70617261676f6e69652f646f637472696e652d63697068657273776565742e737667)](https://packagist.org/packages/paragonie/doctrine-ciphersweet)

Use searchable encryption with [Doctrine ORM](https://github.com/doctrine/orm), powered by [CipherSweet](https://ciphersweet.paragonie.com/).

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

[](#installation)

```
composer require paragonie/doctrine-ciphersweet
```

Usage
-----

[](#usage)

First, you need to create a `ParagonIE\CipherSweet\CipherSweet` object. Please refer to [the CipherSweet docs](https://ciphersweet.paragonie.com/php/setup).

```
use ParagonIE\CipherSweet\CipherSweet;
use ParagonIE\CipherSweet\KeyProvider\StringProvider;

$keyProvider = new StringProvider(random_bytes(32));
$engine = new CipherSweet($keyProvider);
```

Next, create an `EncryptedFieldSubscriber` and register it with your `EntityManager`.

```
use ParagonIE\DoctrineCipher\Event\EncryptedFieldSubscriber;

$subscriber = new EncryptedFieldSubscriber($engine);
$entityManager->getEventManager()->addEventSubscriber($subscriber);
```

Now you can use the `#[Encrypted]` attribute on your entity properties.

```
use Doctrine\ORM\Mapping as ORM;
use ParagonIE\DoctrineCipher\Attribute\Encrypted;

#[ORM\Entity]
class Message
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer')]
    #[ORM\GeneratedValue]
    private int $id;

    #[ORM\Column(type: 'text')]
    #[Encrypted]
    private string $text;

    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    private ?string $textBlindIndexInsensitive;

    public function __construct(string $text)
    {
        $this->text = $text;
    }

    // ... getters and setters
}
```

When you persist an entity, the `EncryptedFieldSubscriber` will automatically encrypt the properties that have the `#[Encrypted]` attribute.

```
$message = new Message('This is a secret message.');
$entityManager->persist($message);
$entityManager->flush();
```

When you retrieve an entity, the encrypted properties will be automatically decrypted.

```
$message = $entityManager->find(Message::class, 1);
echo $message->getText(); // "This is a secret message."
```

### Blind Indexes

[](#blind-indexes)

You can also use blind indexes for searchable encryption. To do this, add a `blindIndexes` argument to the `#[Encrypted]` attribute.

```
use Doctrine\ORM\Mapping as ORM;
use ParagonIE\DoctrineCipher\Attribute\Encrypted;

#[ORM\Entity]
class Message
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer')]
    #[ORM\GeneratedValue]
    private int $id;

    #[ORM\Column(type: 'text')]
    #[Encrypted(blindIndexes: ['insensitive' => 'case-insensitive'])]
    private string $text;

    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    private ?string $textBlindIndexInsensitive;

    public function __construct(string $text)
    {
        $this->text = $text;
    }

    // ... getters and setters
}
```

You also need to register a transformer for the blind index.

```
use ParagonIE\CipherSweet\Transformation\Lowercase;

$subscriber->addTransformer('case-insensitive', Lowercase::class);
```

Now you can query the blind index.

To do so, you must first calculate the blind index for your search term.

```
use ParagonIE\CipherSweet\BlindIndex;
use ParagonIE\CipherSweet\EncryptedField;

// First, you need to get the blind index for your search term.
// Note: The EncryptedField must be configured exactly as it is for the entity.
$encryptedField = new EncryptedField($engine, 'messages', 'text');
$encryptedField->addBlindIndex(new BlindIndex('insensitive', [new Lowercase()]));

$searchTerm = 'this is a secret message.';
$blindIndex = $encryptedField->getBlindIndex($searchTerm, 'insensitive');

// Now you can use this blind index to query the database.
$repository = $entityManager->getRepository(Message::class);
$message = $repository->findOneBy(['textBlindIndexInsensitive' => $blindIndex]);
```

Support Contracts
-----------------

[](#support-contracts)

If your company uses this library in their products or services, you may be interested in [purchasing a support contract from Paragon Initiative Enterprises](https://paragonie.com/enterprise).

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance63

Regular maintenance activity

Popularity26

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

229d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/05d241256cda885139a5697d3bb536b5cec3b430c1adb9c524bf92a37a55758d?d=identicon)[paragonie-scott](/maintainers/paragonie-scott)

---

Top Contributors

[![paragonie-security](https://avatars.githubusercontent.com/u/15914520?v=4)](https://github.com/paragonie-security "paragonie-security (14 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/paragonie-doctrine-ciphersweet/health.svg)

```
[![Health](https://phpackages.com/badges/paragonie-doctrine-ciphersweet/health.svg)](https://phpackages.com/packages/paragonie-doctrine-ciphersweet)
```

###  Alternatives

[spatie/laravel-ciphersweet

Use ciphersweet in your Laravel project

416718.4k1](/packages/spatie-laravel-ciphersweet)[codeconsortium/ccdn-user-security-bundle

CCDN User Security Bundle

60100.7k](/packages/codeconsortium-ccdn-user-security-bundle)[bjorn-voesten/ciphersweet-for-laravel

1411.6k](/packages/bjorn-voesten-ciphersweet-for-laravel)

PHPackages © 2026

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