Encrypt and decrypt strings in PHP.

2.0.2 2019-09-26 12:37 UTC

This package is auto-updated.

Last update: 2021-11-26 19:32:33 UTC


GitHub release License Build Status Code Coverage Scrutinizer Code Quality Total Downloads


Encrypt and decrypt strings in PHP.

This package includes an adapter for Laravel's Encrypter that adheres to my Encrypter interface. This can be used in vanilla PHP. Other implementations might be added in the future.


Install this package through Composer:

composer require codezero/encrypter

Vanilla PHP Implementation

Autoload the vendor classes:

require_once 'vendor/autoload.php'; // Path may vary

Choose a key. You will need the same key that was used to encrypt a string, to decrypt it.

$key = 'my secret key';

And then use the DefaultEncrypter implementation:

$encrypter = new \CodeZero\Encrypter\DefaultEncrypter($key);


Encrypt a string

$encrypted = $encrypter->encrypt('some string');

Decrypt an encrypted string

try {
    $decrypted = $encrypter->decrypt($encrypted);
} catch (\CodeZero\Encrypter\DecryptException $exception) {
    // Decryption failed...


$ composer run test


If you discover any security related issues, please e-mail me instead of using the issue tracker.


The MIT License (MIT). Please see License File for more information.