PHPackages                             michaelmawhinney/cryptex - 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. michaelmawhinney/cryptex

ActiveLibrary[Security](/categories/security)

michaelmawhinney/cryptex
========================

A simple PHP class for 2-way authenticated encryption using XChaCha20 + Poly1305 (libsodium)

v5.0.0(3mo ago)3263[13 issues](https://github.com/michaelmawhinney/Cryptex/issues)MITPHPPHP &gt;=8.3CI passing

Since Feb 2Pushed 4w ago1 watchersCompare

[ Source](https://github.com/michaelmawhinney/Cryptex)[ Packagist](https://packagist.org/packages/michaelmawhinney/cryptex)[ Docs](https://github.com/michaelmawhinney/cryptex)[ RSS](/packages/michaelmawhinney-cryptex/feed)WikiDiscussions main Synced 4w ago

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

[![Cryptex](https://camo.githubusercontent.com/935ca6932a502792f1b65c7249988adace3872e65577ff76e9985e339000cab6/68747470733a2f2f6d69636861656c6d617768696e6e65792e636f6d2f637279707465782f6c6f676f2e676966)](https://camo.githubusercontent.com/935ca6932a502792f1b65c7249988adace3872e65577ff76e9985e339000cab6/68747470733a2f2f6d69636861656c6d617768696e6e65792e636f6d2f637279707465782f6c6f676f2e676966)

Cryptex
=======

[](#cryptex)

Cryptex is a small PHP library for authenticated symmetric encryption using XChaCha20-Poly1305 and Argon2id through PHP's Sodium extension.

Features
--------

[](#features)

- Encrypts and authenticates plaintext with libsodium's XChaCha20-Poly1305 implementation.
- Derives an encryption key from caller-supplied key material and a salt with Argon2id.
- Uses a fresh random nonce for every encryption, so encrypting the same plaintext twice produces different ciphertext.
- Fails closed: tampered data, a wrong key, or a wrong salt cannot produce unauthenticated plaintext.
- Provides a small API: `Cryptex::encrypt()`, `Cryptex::decrypt()`, and `Cryptex::generateSalt()`.

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

[](#requirements)

- PHP 8.3 or newer
- `ext-sodium`

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

[](#installation)

Install Cryptex with Composer:

```
composer require michaelmawhinney/cryptex
```

Quick start
-----------

[](#quick-start)

Generate key material once, keep it protected, and retain the salt used for each ciphertext.

```
