PHPackages                             mmeyer2k/secretbox - 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. mmeyer2k/secretbox

ActiveLibrary[Security](/categories/security)

mmeyer2k/secretbox
==================

A minimalist wrapper for libsodium secretbox

v0.0.0(1y ago)085[1 PRs](https://github.com/mmeyer2k/secretbox/pulls)MITPHPPHP ^8.1CI passing

Since Jan 5Pushed 5mo ago1 watchersCompare

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

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

secretbox
=========

[](#secretbox)

A minimalist [libsodium](https://libsodium.gitbook.io/doc/) secretbox implementation for PHP, supporting key rotation.

[![PHP Tests](https://github.com/mmeyer2k/secretbox/actions/workflows/php-tests.yml/badge.svg)](https://github.com/mmeyer2k/secretbox/actions/workflows/php-tests.yml)

Features
--------

[](#features)

- Encrypt and decrypt messages using libsodium's secretbox
- Support for key rotation (multiple keys for decryption)
- Simple API for secure key management

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

[](#installation)

Install via Composer:

```
composer require mmeyer2k/secretbox
```

Requires PHP 8.2+ and the Sodium extension.

Usage
-----

[](#usage)

Basic encryption and decryption:

```
use \Mmeyer2k\SecretBox\SecretBox;

$key = random_bytes(32); // 32 bytes required

$ciphertext = SecretBox::encrypt('secret message', $key);
$plaintext = SecretBox::decrypt($ciphertext, $key);
```

Key Management
--------------

[](#key-management)

### Creating a Key

[](#creating-a-key)

Generate a secure 32-byte key:

```
head -c 32 /dev/urandom | base64 -w 0
```

### Storing a Key

[](#storing-a-key)

Store keys in environment variables or configuration files as base64 strings. Decode before use:

```
$key = base64_decode('[your base64 key]');
```

### Key Rotation

[](#key-rotation)

Support multiple keys for seamless rotation:

```
$plaintext = SecretBox::decrypt($ciphertext, [
    $oldKey,
    $newKey,
]);
```

Decryption will succeed with any valid key in the array.

Error Handling
--------------

[](#error-handling)

If decryption fails (e.g., no matching key), a `\SodiumException` is thrown:

```
try {
    $plaintext = SecretBox::decrypt($ciphertext, $key);
} catch (\SodiumException $e) {
    // Handle decryption failure
}
```

License
-------

[](#license)

MIT

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance57

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

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

498d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c39fe5f8d80dda8a5735401c12cb631d5e17050f7baa7cd3f0f384167fb45db?d=identicon)[mmeyer2k](/maintainers/mmeyer2k)

---

Top Contributors

[![mmeyer2k](https://avatars.githubusercontent.com/u/1887431?v=4)](https://github.com/mmeyer2k "mmeyer2k (16 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mmeyer2k-secretbox/health.svg)

```
[![Health](https://phpackages.com/badges/mmeyer2k-secretbox/health.svg)](https://phpackages.com/packages/mmeyer2k-secretbox)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[mews/purifier

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

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41478.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[illuminate/encryption

The Illuminate Encryption package.

9229.7M280](/packages/illuminate-encryption)[paragonie/hidden-string

Encapsulate strings in an object to hide them from stack traces

7410.6M39](/packages/paragonie-hidden-string)

PHPackages © 2026

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