PHPackages                             cipherstash/protectphp-ffi - 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. cipherstash/protectphp-ffi

ActiveLibrary[Security](/categories/security)

cipherstash/protectphp-ffi
==========================

PHP bindings for the CipherStash Client SDK

288Rust

Since Jul 25Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/cipherstash/protectphp-ffi)[ Packagist](https://packagist.org/packages/cipherstash/protectphp-ffi)[ RSS](/packages/cipherstash-protectphp-ffi/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Protect.php FFI
===============

[](#protectphp-ffi)

Protect.php FFI provides PHP bindings for the [CipherStash Client SDK](https://crates.io/crates/cipherstash-client) via PHP's [Foreign Function Interface (FFI)](https://www.php.net/manual/en/book.ffi.php). Field-level encryption operations happen directly in your application using a unique key for each encrypted value, managed by CipherStash [ZeroKMS](https://cipherstash.com/products/zerokms) and backed by [AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html). The encrypted data can be stored in any JSONB-compatible database while maintaining searchability on PostgreSQL.

This library operates at a low level, providing direct access to the native cryptographic operations. It requires manual memory management and detailed encryption configuration, designed for advanced use cases where you need fine-grained control over the encryption process.

Important

For most applications, you'll want to use the [Protect.php](https://github.com/cipherstash/protectphp) library instead, as it provides a more convenient API built on top of these bindings.

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

[](#installation)

Install Protect.php FFI via Composer:

```
composer require cipherstash/protectphp-ffi
```

Requirements
------------

[](#requirements)

Protect.php FFI requires PHP 8.1 or higher with the FFI extension (included in most distributions). This library includes prebuilt native libraries for the following platforms:

- macOS: Apple Silicon (ARM64) and Intel (x86\_64) processors
- Linux: x86\_64 and ARM64 architectures with GNU libc
- Windows: x86\_64 architecture with MSVC runtime

Configuration
-------------

[](#configuration)

Before using Protect.php FFI, you must configure your CipherStash credentials. Set these environment variables in your application:

```
CS_CLIENT_ID=your-client-id
CS_CLIENT_ACCESS_KEY=your-client-access-key
CS_CLIENT_KEY=your-client-key
CS_WORKSPACE_CRN=your-workspace-crn
```

Credentials can be generated by logging in or signing up for CipherStash and setting up a new workspace via the [CipherStash CLI](https://cipherstash.com/docs/sdk/how-to/cli) or [CipherStash Dashboard](https://dashboard.cipherstash.com/).

Database Setup
--------------

[](#database-setup)

Protect.php FFI works with any database that supports JSONB storage. The encrypted data is structured as an [Encrypt Query Language (EQL)](https://github.com/cipherstash/encrypt-query-language) JSON payload.

For advanced querying capabilities (searching, sorting, filtering), you'll need PostgreSQL with the EQL extension. EQL provides the `eql_v2_encrypted` type:

```
CREATE TABLE users (
    id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    email eql_v2_encrypted,
    name eql_v2_encrypted,
    balance eql_v2_encrypted,
    contact eql_v2_encrypted,
    notes eql_v2_encrypted,
    CONSTRAINT unique_email UNIQUE ((email->>'hm')) -- Enforce unique emails
);
```

See the [EQL installation instructions](https://github.com/cipherstash/encrypt-query-language#installation) to get started.

Encryption Configuration
------------------------

[](#encryption-configuration)

The encryption configuration defines your schema and determines what types of operations are supported on encrypted data. It consists of a JSON structure that specifies tables, columns, data types, and encryption indexes.

Basic structure:

```
$config = [
    'v' => 2,
    'tables' => [
        'users' => [
            'email' => [
                'cast_as' => 'text',
                'indexes' => [
                    'unique' => (object) [],
                    'match' => (object) [],
                ],
            ],
            'balance' => [
                'cast_as' => 'int',
                'indexes' => [
                    'unique' => (object) [],
                    'ore' => (object) [],
                ],
            ],
            'notes' => [
                'cast_as' => 'text',
                'indexes' => [
                    'match' => (object) [],
                ],
            ],
            'contact' => [
                'cast_as' => 'jsonb',
                'indexes' => [
                    'ste_vec' => [
                        'prefix' => 'users.contact',
                    ],
                ],
            ],
        ],
    ],
];
```

Configuration parameters:

ParameterTypeRequiredDescription`v``int`✓Schema version for backward compatibility (must be `2`)`tables``object`✓Table definitions containing column configurations`tables.``object`✓Column definitions for the specified table`tables..``object`✓Configuration for the specified column`tables...cast_as``string`✗Data type for processing before encryption (defaults to `text`)`tables...indexes``object`✗Encryption indexes for query patterns`tables...indexes.``object`✗Configuration parameters for the specified index type (see individual index type documentation)`tables...indexes..``mixed`✗Index-specific configuration parameterImportant

When configuring indexes without parameters, you must use `(object) []` instead of an empty array `[]`. This ensures PHP's `json_encode()` produces a JSON object (`{}`) rather than a JSON array (`[]`), which is required by the native library's configuration parser.

### Data Types

[](#data-types)

The `cast_as` parameter determines how plaintext data is processed before encryption:

TypeDescriptionExample Input`text`String data`john@example.com``boolean`Boolean values`true` or `false``small_int`16-bit integer numbers`32767``int`32-bit integer numbers`2147483647``big_int`64-bit integer numbers`9223372036854775807``real`Single-precision floating point`25.99``double`Double-precision floating point`3.141592653589793``date`Date strings in ISO format`2020-11-10``jsonb`JSON data`{"key": "value"}`### Index Types

[](#index-types)

The `indexes` parameter determines what queries are supported on encrypted data:

Index TypeDescriptionResponse ParameterSupported Queries`unique`Exact equality queries and uniqueness constraints`hm``=``ore`Equality, range comparisons, range queries, and ordering`ob``=`, `>`, ``, ` [
    'email' => [
        'cast_as' => 'text',
        'indexes' => [
            'unique' => (object) [], // Uses defaults
        ],
    ],
],
```

Configuration parameters:

ParameterTypeRequiredDefaultDescription`token_filters``array`✗`[]`Text processing filters applied before hashing`token_filters[].kind``string`✗-Filter type: `downcase` to convert to lowercaseWith custom parameters:

```
'users' => [
    'email' => [
        'cast_as' => 'text',
        'indexes' => [
            'unique' => [
                'token_filters' => [
                    ['kind' => 'downcase'],
                ],
            ],
        ],
    ],
],
```

For database-level uniqueness constraints, add a unique constraint on the `hm` response parameter:

```
CONSTRAINT unique_email UNIQUE ((email->>'hm'))
```

#### Order Revealing Encryption Index (`ore`)

[](#order-revealing-encryption-index-ore)

Enables equality, range operations, and ordering on encrypted data. Uses the `ob` response parameter to create order-preserving encrypted values for equality checks, range comparisons, and sorting operations.

Basic usage:

```
'users' => [
    'balance' => [
        'cast_as' => 'int',
        'indexes' => [
            'ore' => (object) [],
        ],
    ],
],
```

Configuration parameters:

*This index type has no configurable parameters.*

#### Match Index (`match`)

[](#match-index-match)

Enables full-text search on encrypted text data using bloom filters. Uses the `bf` response parameter to create bloom filter representations of tokenized text for probabilistic matching.

Basic usage:

```
'users' => [
    'notes' => [
        'cast_as' => 'text',
        'indexes' => [
            'match' => (object) [], // Uses defaults
        ],
    ],
],
```

Configuration parameters:

ParameterTypeRequiredDefaultDescription`tokenizer``object`✗`{"kind": "standard"}`Text tokenization method`tokenizer.kind``string`✗`standard`Tokenizer type: `standard` or `ngram``tokenizer.token_length``integer`✗`3`Token length for ngram tokenizer`token_filters``array`✗`[]`Text processing filters`token_filters[].kind``string`✗-Filter type: `downcase``k``integer`✗`6`Hash function count for bloom filter`m``integer`✗`2048`Bloom filter size in bits`include_original``boolean`✗`false`Include original text in search resultsWith custom parameters:

```
'users' => [
    'notes' => [
        'cast_as' => 'text',
        'indexes' => [
            'match' => [
                'tokenizer' => [
                    'kind' => 'ngram',
                    'token_length' => 3,
                ],
                'token_filters' => [
                    ['kind' => 'downcase'],
                ],
                'k' => 8,
                'm' => 1024,
                'include_original' => true,
            ],
        ],
    ],
],
```

#### Structured Text Encryption Vector Index (`ste_vec`)

[](#structured-text-encryption-vector-index-ste_vec)

Enables containment queries on encrypted JSONB data. Uses the `sv` response parameter to create structured text encryption vectors that preserve JSON path relationships for encrypted JSONB containment matching.

Basic usage:

```
'users' => [
    'contact' => [
        'cast_as' => 'jsonb',
        'indexes' => [
            'ste_vec' => [
                'prefix' => 'users.contact',
            ],
        ],
    ],
],
```

Configuration parameters:

ParameterTypeRequiredDefaultDescription`prefix``string`✓-Domain separator for cryptographic hashing that must be unique per column (recommended format is `table.column`)Creating a Client
-----------------

[](#creating-a-client)

Create a client instance with your encryption configuration to perform encryption and decryption operations:

```
use CipherStash\Protect\FFI\Client;

$client = new Client;

$config = [
    'v' => 2,
    'tables' => [
        'users' => [
            'email' => [
                'cast_as' => 'text',
                'indexes' => [
                    'unique' => (object) [],
                ],
            ],
            'balance' => [
                'cast_as' => 'int',
                'indexes' => [
                    'unique' => (object) [],
                    'ore' => (object) [],
                ],
            ],
            'notes' => [
                'cast_as' => 'text',
                'indexes' => [
                    'match' => (object) [],
                ],
            ],
            'contact' => [
                'cast_as' => 'jsonb',
                'indexes' => [
                    'ste_vec' => [
                        'prefix' => 'users.contact',
                    ],
                ],
            ],
        ],
    ],
];

$clientPtr = null;

try {
    $configJson = json_encode($config, JSON_THROW_ON_ERROR);
    $clientPtr = $client->newClient($configJson);

    // ...
} finally {
    // Always cleanup to prevent memory leaks
    if ($clientPtr !== null) {
        $client->freeClient($clientPtr);
    }
}
```

Encrypting Data
---------------

[](#encrypting-data)

Encrypt plaintext data for specific table columns using the `encrypt()` method. This method accepts a client pointer and individual parameters for the plaintext string, column name, and table name. The encryption configuration defines how each column should be encrypted and what data type it represents:

```
use CipherStash\Protect\FFI\Client;

$client = new Client;

$config = [
    'v' => 2,
    'tables' => [
        'users' => [
            'email' => [
                'cast_as' => 'text',
                'indexes' => [
                    'unique' => (object) [],
                    'match' => (object) [],
                ],
            ],
        ],
    ],
];

$clientPtr = null;

try {
    $configJson = json_encode($config, JSON_THROW_ON_ERROR);
    $clientPtr = $client->newClient($configJson);

    $encryptResultJson = $client->encrypt(
        client: $clientPtr,
        plaintext: 'john@example.com',
        column: 'email',
        table: 'users',
    );

    // {"k":"ct","c":"mBbKlk}G7QdaGiNj$dL7#+AOrA^}*VJx...","dt":"text","hm":"f3ca71fd39ae9d3d1d1fc25141bcb6da...","ob":null,"bf":[1124,2134,987,1456,743,2201],"i":{"t":"users","c":"email"},"v":2}
} finally {
    if ($clientPtr !== null) {
        $client->freeClient($clientPtr);
    }
}
```

Important

The `plaintext` parameter must always be a string. The `cast_as` configuration parameter determines how the string is processed by the native library before encryption, not the input format, and indicates the intended data type for parsing decrypted strings. Convert all values to strings before calling this method.

### Encryption Response

[](#encryption-response)

The `encrypt()` method returns a JSON string containing the encrypted envelope. The response format depends on the configured indexes.

#### Standard Indexes Response

[](#standard-indexes-response)

For columns configured with the `unique`, `ore`, and/or `match` indexes:

```
{
    "k": "ct",
    "c": "mBbKlk}G7QdaGiNj$dL7#+AOrA^}*VJx...",
    "dt": "text",
    "hm": "f3ca71fd39ae9d3d1d1fc25141bcb6da...",
    "ob": null,
    "bf": [1124,2134,987,1456,743,2201],
    "i": {
        "t": "users",
        "c": "email"
    },
    "v": 2
}
```

Response parameters:

ParameterTypeSourceDescription`k``string`AlwaysKey type identifier (always `ct` for ciphertext)`c``string`AlwaysBase85-encoded ciphertext containing the encrypted data`dt``string`AlwaysData type for casting (from `cast_as` configuration parameter)`hm``string|null``unique`HMAC index for exact equality queries and uniqueness constraints`ob``array|null``ore`Order-revealing encryption index for range queries`bf``array|null``match`Bloom filter index for full-text search queries`i``object`AlwaysTable and column identifier for this encrypted value: `{"t":"table","c":"column"}``v``int`AlwaysSchema version for backward compatibility#### STE Vec Index Response

[](#ste-vec-index-response)

For columns configured with the `ste_vec` index:

```
{
    "k": "sv",
    "c": "mBbLQ2^Io|1eh_K2*n^LSCVVQuGhkL>w...",
    "dt": "jsonb",
    "sv": [
        {
            "s": "dd4659b9c279af040dd05ce21b2a22f7...",
            "t": "22303061363334333330316661653633...",
            "r": "mBbLQ2^Io|1eh_K2*n^LSCVVQuGhkL>w...",
            "pa": false
        }
    ],
    "i": {
        "t": "users",
        "c": "contact"
    },
    "v": 2
}
```

Response parameters:

ParameterTypeSourceDescription`k``string`AlwaysKey type identifier (always `sv` for structured vector)`c``string`AlwaysBase85-encoded ciphertext containing the encrypted data`dt``string`AlwaysData type for casting (from `cast_as` configuration parameter)`sv``array|null``ste_vec`Structured text encryption vector for JSONB containment queries`sv[].s``string``ste_vec`Tokenized selector representing the encrypted JSON path to the value`sv[].t``string``ste_vec`Encrypted term value for equality and order-preserving queries`sv[].r``string``ste_vec`Base85-encoded ciphertext containing the encrypted record data`sv[].pa``boolean``ste_vec`Whether the parent JSON element is an array`i``object`AlwaysTable and column identifier for this encrypted value: `{"t":"table","c":"column"}``v``int`AlwaysSchema version for backward compatibilityDecrypting Data
---------------

[](#decrypting-data)

Decrypt ciphertext back to its original plaintext using the `decrypt()` method. This method accepts a client pointer and the base85-encoded ciphertext string from the encryption response:

```
use CipherStash\Protect\FFI\Client;

$client = new Client;

$config = [
    'v' => 2,
    'tables' => [
        'users' => [
            'email' => [
                'cast_as' => 'text',
                'indexes' => [
                    'unique' => (object) [],
                    'match' => (object) [],
                ],
            ],
        ],
    ],
];

$clientPtr = null;

try {
    $configJson = json_encode($config, JSON_THROW_ON_ERROR);
    $clientPtr = $client->newClient($configJson);

    $encryptResultJson = $client->encrypt(
        client: $clientPtr,
        plaintext: 'john@example.com',
        column: 'email',
        table: 'users',
    );

    $encryptResult = json_decode(json: $encryptResultJson, associative: true, flags: JSON_THROW_ON_ERROR);

    $ciphertext = $encryptResult['c'];

    $decryptResult = $client->decrypt($clientPtr, $ciphertext); // john@example.com
} finally {
    if ($clientPtr !== null) {
        $client->freeClient($clientPtr);
    }
}
```

Returns the decrypted plaintext as a string.

Encryption Context
------------------

[](#encryption-context)

Provide additional encryption context for an additional layer of security by binding encrypted data to specific contextual information of your choosing. This prevents data encrypted with one context from being decrypted with a different context, even when using the same encryption keys.

### Context Types

[](#context-types)

The `context` parameter determines what contextual authentication is supported:

Context TypeSupported Index TypesDescription`identity_claim``unique`, `ore`, `match`Identity-aware encryption using JWT claims (requires CTS authentication)`tag``unique`, `ore`, `match`Label-aware encryption using string tags`value``unique`, `ore`, `match`Attribute-aware encryption using key-value pairsImportant

Encryption context is not supported with `ste_vec` indexes and will cause decryption to fail.

### Identity Claim Context

[](#identity-claim-context)

Identity claim context binds encrypted data to specific user identities using JWT claims. This enables identity-aware encryption where data can only be decrypted by authenticated users who match the identity criteria.

Identity claim context requires [CipherStash Token Service (CTS)](https://cipherstash.com/docs/cts/about) authentication for both encryption and decryption operations. The FFI layer supports identity claim parsing but cannot perform cryptographic operations with identity claims without valid CTS tokens. Use the [Protect.php](https://github.com/cipherstash/protectphp) library for this type of encryption context.

### Tag Context

[](#tag-context)

Tag context binds encrypted data to specific string labels. This enables label-aware encryption where data can only be decrypted when the same tag context is provided:

```
use CipherStash\Protect\FFI\Client;

$client = new Client;

$config = [
    'v' => 2,
    'tables' => [
        'users' => [
            'email' => [
                'cast_as' => 'text',
                'indexes' => [
                    'unique' => (object) [],
                    'match' => (object) [],
                ],
            ],
        ],
    ],
];

$clientPtr = null;

try {
    $configJson = json_encode($config, JSON_THROW_ON_ERROR);
    $clientPtr = $client->newClient($configJson);

    $context = [
        'tag' => ['pii', 'hipaa'],
    ];

    $contextJson = json_encode($context, JSON_THROW_ON_ERROR);

    $encryptResultJson = $client->encrypt(
        client: $clientPtr,
        plaintext: 'john@example.com',
        column: 'email',
        table: 'users',
        contextJson: $contextJson,
    );

    $encryptResult = json_decode(json: $encryptResultJson, associative: true, flags: JSON_THROW_ON_ERROR);

    $ciphertext = $encryptResult['c'];

    $decryptResult = $client->decrypt($clientPtr, $ciphertext, $contextJson); // john@example.com
} finally {
    if ($clientPtr !== null) {
        $client->freeClient($clientPtr);
    }
}
```

### Value Context

[](#value-context)

Value context binds encrypted data to specific key-value pairs. This enables attribute-aware encryption where data can only be decrypted when the same value context is provided:

```
use CipherStash\Protect\FFI\Client;

$client = new Client;

$config = [
    'v' => 2,
    'tables' => [
        'users' => [
            'email' => [
                'cast_as' => 'text',
                'indexes' => [
                    'unique' => (object) [],
                    'match' => (object) [],
                ],
            ],
        ],
    ],
];

$clientPtr = null;

try {
    $configJson = json_encode($config, JSON_THROW_ON_ERROR);
    $clientPtr = $client->newClient($configJson);

    $context = [
        'value' => [
            ['key' => 'tenant_id', 'value' => 'tenant_2ynTJf38e9HvuAO8jaX5kAyVaKI'],
            ['key' => 'role', 'value' => 'admin'],
        ],
    ];

    $contextJson = json_encode($context, JSON_THROW_ON_ERROR);

    $encryptResultJson = $client->encrypt(
        client: $clientPtr,
        plaintext: 'john@example.com',
        column: 'email',
        table: 'users',
        contextJson: $contextJson,
    );

    $encryptResult = json_decode(json: $encryptResultJson, associative: true, flags: JSON_THROW_ON_ERROR);

    $ciphertext = $encryptResult['c'];

    $decryptResult = $client->decrypt($clientPtr, $ciphertext, $contextJson); // john@example.com
} finally {
    if ($clientPtr !== null) {
        $client->freeClient($clientPtr);
    }
}
```

Warning

You must use the same context for both encryption and decryption operations. Wrong contexts will result in decryption failures.

Bulk Operations
---------------

[](#bulk-operations)

For improved performance when handling multiple records, use bulk encryption and decryption operations:

### Bulk Encryption

[](#bulk-encryption)

Encrypt multiple plaintext strings using the `encryptBulk()` method. This method accepts a client pointer and a JSON array of objects, where each object specifies the `plaintext`, `column`, `table`, and optional `context` for encryption:

```
use CipherStash\Protect\FFI\Client;

$client = new Client;

$config = [
    'v' => 2,
    'tables' => [
        'users' => [
            'email' => [
                'cast_as' => 'text',
                'indexes' => [
                    'unique' => (object) [],
                    'match' => (object) [],
                ],
            ],
            'notes' => [
                'cast_as' => 'text',
                'indexes' => [
                    'match' => (object) [],
                ],
            ],
        ],
    ],
];

$clientPtr = null;

try {
    $configJson = json_encode($config, JSON_THROW_ON_ERROR);
    $clientPtr = $client->newClient($configJson);

    $items = [
        [
            'plaintext' => 'john@example.com',
            'column' => 'email',
            'table' => 'users',
        ],
        [
            'plaintext' => 'Account flagged for fraud monitoring after suspicious transaction pattern detected. Customer disputed charges on 2007-07-27. Priority support required for high-value client.',
            'column' => 'notes',
            'table' => 'users',
        ],
    ];

    $itemsJson = json_encode($items, JSON_THROW_ON_ERROR);
    $encryptResultsJson = $client->encryptBulk($clientPtr, $itemsJson);
    // [{"k":"ct","c":"mBbKuXT|+vBh~K2WV-!n5_W3DBFd4`Mp...","dt":"text","hm":"f3ca71fd39ae9d3d1d1fc25141bcb6da...","ob":null,"bf":[1124,2134,987,1456,743,2201],"i":{"t":"users","c":"email"},"v":2},{"k":"ct","c":"mBbJBcAYctW$Gy)vK2)Y$&nBBKz{oL1...","context":{"tag":["pii","hipaa"]}},{"ciphertext":"mBbJf;r}uFEp7Tg...",
            "pa": false
        },
        {
            "s": "df08a4c4157bdb5bf6fa9be89cf18d10...",
            "t": "22303063343133306135646334356130...",
            "r": "mBbLkCZcaJ2U|G333rRC>f;r}E&d@?`;...",
            "pa": false
        }
    ],
    "i": {
        "t": "users",
        "c": "contact"
    }
}
```

Response parameters:

ParameterTypeSourceDescription`sv``array|null``ste_vec`Structured text encryption vector for JSONB containment queries`sv[].s``string``ste_vec`Tokenized selector representing the encrypted JSON path to the value`sv[].t``string``ste_vec`Encrypted term value for equality and order-preserving queries`sv[].r``string``ste_vec`Base85-encoded ciphertext containing the encrypted record data`sv[].pa``boolean``ste_vec`Whether the parent JSON element is an array`i``object`AlwaysTable and column identifier for this encrypted value: `{"t":"table","c":"column"}`Error Handling
--------------

[](#error-handling)

Protect.php FFI operations may throw `FFIException` exceptions when errors occur during client, encryption, or decryption operations. Proper error handling ensures your application can gracefully handle configuration issues, network problems, or invalid data scenarios.

### Exception Types

[](#exception-types)

All FFI operations throw `FFIException` exceptions that contain descriptive error messages:

```
use CipherStash\Protect\FFI\Client;
use CipherStash\Protect\FFI\Exceptions\FFIException;

$client = new Client;

$config = [
    'v' => 2,
    'tables' => [
        'users' => [
            'email' => [
                'cast_as' => 'text',
                'indexes' => [
                    'unique' => (object) [],
                    'match' => (object) [],
                ],
            ],
        ],
    ],
];

$clientPtr = null;

try {
    $configJson = json_encode($config, JSON_THROW_ON_ERROR);
    $clientPtr = $client->newClient($configJson);

    $encryptResultJson = $client->encrypt(
        client: $clientPtr,
        plaintext: 'john@example.com',
        column: 'email',
        table: 'users',
    );

    $encryptResult = json_decode(json: $encryptResultJson, associative: true, flags: JSON_THROW_ON_ERROR);
    $ciphertext = $encryptResult['c']; // mBbKlk}G7QdaGiNj$dL7#+AOrA^}*VJx...
} catch (FFIException $e) {
    // Handle FFI errors
    // ...
} finally {
    if ($clientPtr !== null) {
        $client->freeClient($clientPtr);
    }
}
```

Contributing
------------

[](#contributing)

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 80% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cecd6920303588dd8868cefeccada5235fe19f941fb96526ff848b8690157a75?d=identicon)[cs-cjbrewer](/maintainers/cs-cjbrewer)

---

Top Contributors

[![coreyhn](https://avatars.githubusercontent.com/u/114305474?v=4)](https://github.com/coreyhn "coreyhn (60 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (9 commits)")[![calvinbrewer](https://avatars.githubusercontent.com/u/10352306?v=4)](https://github.com/calvinbrewer "calvinbrewer (6 commits)")

### Embed Badge

![Health badge](/badges/cipherstash-protectphp-ffi/health.svg)

```
[![Health](https://phpackages.com/badges/cipherstash-protectphp-ffi/health.svg)](https://phpackages.com/packages/cipherstash-protectphp-ffi)
```

###  Alternatives

[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k18.7M143](/packages/mews-purifier)[paragonie/ecc

PHP Elliptic Curve Cryptography library

24820.0k38](/packages/paragonie-ecc)

PHPackages © 2026

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