PHPackages                             threadi/crypt-for-wordpress - 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. threadi/crypt-for-wordpress

ActiveLibrary

threadi/crypt-for-wordpress
===========================

1.0.3(6d ago)08GPL-3.0-or-laterPHPCI passing

Since Mar 14Pushed 6d agoCompare

[ Source](https://github.com/threadi/crypt-for-wordpress)[ Packagist](https://packagist.org/packages/threadi/crypt-for-wordpress)[ RSS](/packages/threadi-crypt-for-wordpress/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (8)Versions (11)Used By (0)

Crypt for WordPress
===================

[](#crypt-for-wordpress)

This repository contains the source code for the Composer package “Crypt for WordPress”. It can be used in plugins or themes to encrypt strings.

How it works
------------

[](#how-it-works)

A hash key is generated for each plugin or theme, that is used for all encryption and decryption. This key is stored in the **wp-config.php** file or, if using a MU plugin, within the WordPress installation itself. As a result, it is not stored in the database where the encrypted data resides, keeping the key and the data separate. This makes it more difficult for attackers to decrypt the data, as they would need both to be successful.

The **wp-config.php** file is primarily used for this purpose. If this file is not writable (that is the case with some hosting providers), a Must-Use plugin is generated and stored. Optionally, you can force the usage of a Must-Use plugin for each plugin or theme (see Settings below).

### Hint

[](#hint)

Data encryption is not a silver bullet for protecting data. Projects that involve sensitive data should be secured through additional measures in addition to encryption. These include, for example, security plugins. This Composer package is not the only solution for this, but it can help.

Demo
----

[](#demo)

[This demo plugin](https://github.com/threadi/crypt-for-wordpress-demo) demonstrates how the encryption could be used.

Use cases
---------

[](#use-cases)

- You allow users of your plugin to enter API credentials and want to store them securely in the database.
- You allow users to enter FTP credentials and want to store them securely in the database.
- You want users to enter JSON authentication data and store it securely.
- You collect personal data - for example, from job applicants or customers - on your website, and this data must be stored securely.

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

[](#requirements)

- *composer* to install this package.
- WordPress-plugin or theme to embed them in your project.

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

[](#installation)

1. `composer require threadi/crypt-for-wordpress`
2. Add the following codes in your plugin or theme:

```
$crypt = new \CryptForWordPress\Crypt();
$crypt->set_slug( 'your-plugin-slug' ); // your plugin slug.
$crypt->set_plugin_file( __FILE__ ); // your plugin file.

```

### Parameters

[](#parameters)

#### set\_slug()

[](#set_slug)

Use your plugin- or theme-slug. This is required.

#### set\_plugin\_file()

[](#set_plugin_file)

Use your plugin- or theme-main-file. This is required.

#### set\_method\_config()

[](#set_method_config)

Set your custom configuration for the supported methods as array. This is optional, all options are optional.

Format:

```
array(
    'force_method' => 'openssl', // openssl or sodium.
    'openssl' => array(
        'hash_type' => 'hash_pbkdf2', // hash_pbkdf2 or hash.
        'hash_algorithm' => 'sha256' // see hints below.
        'force_mu_plugin => false, // true to force the usage of an MU-plugin to save the hashed key.
    )
    'sodium' => array(
        'hash_type' => 'sodium_crypto_aead_xchacha20poly1305_ietf_keygen' // one of: sodium_crypto_aead_xchacha20poly1305_ietf_keygen, sodium_crypto_secretbox_keygen, sodium_crypto_auth_keygen, sodium_crypto_generichash_keygen, sodium_crypto_kdf_keygen, random_bytes
    )
)

```

##### Hint about usage of ciphers

[](#hint-about-usage-of-ciphers)

In March 2026 you should only use one of these ciphers:

- aes-256-gcm
- aes-256-cbc
- chacha20-poly1305

##### Hint about changes

[](#hint-about-changes)

If you change any of these settings, the changes will apply to newly encrypted strings. Strings that have already been encrypted will not be altered. Depending on the change, this could result in strings that were encrypted before the change no longer being decryptable.

Usage
-----

[](#usage)

### Encrypt

[](#encrypt)

To encrypt a plain string use:

```
$encrypted = $crypt->encrypt( 'My string to encrypt.' );

```

### Decrypt

[](#decrypt)

To decrypt an encrypted string use:

```
$decrypted = $crypt->decrypt( 'My encrypted string to encrypt.' );

```

Uninstall
---------

[](#uninstall)

Use these code to remove the settings during uninstallation of your theme or plugin:

```
$crypt = new \CryptForWordPress\Crypt();
$crypt->set_slug( 'your-plugin-slug' ); // your plugin slug.
$crypt->set_plugin_file( __FILE__ ); // your plugin file.
$crypt->uninstall();

```

Check for WordPress Coding Standards
------------------------------------

[](#check-for-wordpress-coding-standards)

### Initialize

[](#initialize)

`composer install`

### Run

[](#run)

`vendor/bin/phpcs --standard=ruleset.xml vendor/threadi/easy-directory-listing-for-wordpress/`

### Repair

[](#repair)

`vendor/bin/phpcbf --standard=ruleset.xml vendor/threadi/easy-directory-listing-for-wordpress/`

Analyse with PHPStan
--------------------

[](#analyse-with-phpstan)

`vendor/bin/phpstan analyse`

###  Health Score

39

—

LowBetter than 87% of packages

Maintenance98

Actively maintained with recent releases

Popularity7

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

Every ~0 days

Total

4

Last Release

6d ago

### Community

Maintainers

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

---

Top Contributors

[![threadi](https://avatars.githubusercontent.com/u/16623633?v=4)](https://github.com/threadi "threadi (21 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/threadi-crypt-for-wordpress/health.svg)

```
[![Health](https://phpackages.com/badges/threadi-crypt-for-wordpress/health.svg)](https://phpackages.com/packages/threadi-crypt-for-wordpress)
```

PHPackages © 2026

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