arraypress / wp-encryption-utils
A simple utility library for encrypting and decrypting WordPress data including options, settings, meta, and transients.
Requires
- php: >=8.3
- ext-openssl: *
Requires (Dev)
- phpcompatibility/phpcompatibility-wp: ^2.1
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^3.13.5
- wp-coding-standards/wpcs: ^3.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Store an API key in the options table without storing it in the clear.
What it does
A plugin that talks to Stripe or a courier has a secret key, and the usual
home for it is wp_options in plain text — readable by anything with
database access, and included in every backup and staging copy.
This encrypts on the way in and decrypts on the way out, using a key derived from the site's own salts, so nothing extra has to be configured. Read the option the normal way and you get the value; read the database and you get ciphertext.
Features
- Encrypt an option on save and decrypt it on read, transparently
- Derive the key from the site's salts, with no extra configuration
- Let a constant in
wp-config.phpoverride the stored value, for staging - Tell whether a stored value is encrypted, so old plaintext still works
- Re-encrypt everything under a new key, when the salts are rotated
- Describe where a value came from, to show in a settings screen
Installation
composer require arraypress/wp-encryption-utils
Quick start
use ArrayPress\EncryptionUtils\Manager; $secrets = new Manager( 'myplugin' ); $secrets->update_option( 'stripe_secret_key', $key ); $key = $secrets->get_option( 'stripe_secret_key' );
The value in the database is ciphertext. The value your code sees is the key.
What it does not do
The key comes from the site's salts, which are in wp-config.php — so this
protects against a leaked database dump, not against someone who already has
the filesystem. That is the threat worth defending here, and it is a real
one: database backups travel far more freely than wp-config.php does.
Requirements
- PHP 8.3 or later
- WordPress 7.1 or later
- The OpenSSL extension
License
GPL-2.0-or-later