codezero-be / encrypter by codezero

Encrypt and decrypt strings in PHP.
56,062
2
4
Package Data
Maintainer Username: codezero
Maintainer Contact: ivan@codezero.be (Ivan Vermeyen)
Package Create Date: 2015-03-27
Package Last Update: 2019-09-26
Language: PHP
License: MIT
Last Refreshed: 2024-04-19 03:00:18
Package Statistics
Total Downloads: 56,062
Monthly Downloads: 1,624
Daily Downloads: 77
Total Stars: 2
Total Watchers: 4
Total Forks: 1
Total Open Issues: 0

Encrypter

GitHub release License Build Status Scrutinizer 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.

Installation

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);

Usage

Encrypt a string

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

Decrypt an encrypted string

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

Testing

$ vendor/bin/phpspec run

Security

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

License

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


Analytics