New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

taylornetwork/encrypter

A custom encrypter class that uses Laravel's Encrypter class with a custom key instead of the application key.
161
Install
composer require taylornetwork/encrypter
Latest Version:1.0.1
PHP:>=5.4.0
Laravel:5
Last Updated:Nov 11, 2018
Links: GitHub  ·  Packagist
Maintainer: samueljtaylor

Custom Encrypter for Laravel

This package uses Laravel's encryption but allows you to specify a custom passphrase instead of using the application key. This can be useful if some of the database data should be encrypted so that only someone with the passphrase can decrypt it.

Install

Via Composer

$ composer require taylornetwork/encrypter

Setup

TaylorNetwork\Encrypter\Encrypter is ready to run right out of the box.

Usage

Instantiate TaylorNetwork\Encrypter\Encrypter

The class requires 1 parameter, the passphrase you want to encrypt/decrypt with.

$passphrase = 'secret 123';

$encrypter = new TaylorNetwork\Encrypter\Encrypter($passphrase);

Note: Laravel's Encrypter class requires a passphrase of exactly 16 characters, TaylorNetwork\Encrypter\Encrypter will lengthen or shorten the supplied passphrase and then encode it using base64 before passing it to Laravel's Encrypter class so that you can supply any length of passphrase you want.

Available Methods

encrypt (mixed $data)

Encrypts the data given or returns false if the encryption failed.

$data = 'This is some data to encrypt';

$encrypter->encrypt($data);

Returns

'eyJpdiI6Ikc5aVdmUzhWcTRIM2xaMFZtQmVhamc9PSIsInZhbHVlIjoidFJmZHY3c1pcL25MZUtpOGlaM1NYa0JEY0FtbGtKTVVVZnRwaXJJbkNkU2srR3BPNlwvTlwvQ24xM0VUZ1lsc2xSMCIsIm1hYyI6ImZjYTU1YzU5NjFhYWM3NTNkOTFiNDk5YTNhMzIwMzhiMzQ0NjZhMDQyNWFjMTExZWVjY2QxOGM5NGExNmRjMGIifQ=='
decrypt (string $encryptedData)

Decrypts the data given or returns false if the decryption failed.

$data = 'eyJpdiI6Ikc5aVdmUzhWcTRIM2xaMFZtQmVhamc9PSIsInZhbHVlIjoidFJmZHY3c1pcL25MZUtpOGlaM1NYa0JEY0FtbGtKTVVVZnRwaXJJbkNkU2srR3BPNlwvTlwvQ24xM0VUZ1lsc2xSMCIsIm1hYyI6ImZjYTU1YzU5NjFhYWM3NTNkOTFiNDk5YTNhMzIwMzhiMzQ0NjZhMDQyNWFjMTExZWVjY2QxOGM5NGExNmRjMGIifQ==';

$encrypter->decrypt($data);

Returns

'This is some data to encrypt'

Credits

License

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

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

648,266,899 9,701
laravel/framework

The Laravel Framework.

604,216,237 34,982
laravel/tinker

Powerful REPL for the Laravel framework.

512,508,631 7,443
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

429,221,767 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

407,699,310 4,663

Version History

Version Released PHP Laravel License
1.0.1 >=5.4.0 5.*.*
1.0.0 >=5.4.0 5.3.*