hieblmedia/simple-php-encrypter-decrypter

Simple Encrypt/Decrypt PHP Class

dev-master 2020-01-24 04:26 UTC

This package is not auto-updated.

Last update: 2025-04-12 17:04:43 UTC


README

Encrypter is a simple class to encode/decode data with an secure key.

Installing via Composer

The recommended way to install it through Composer.

Install Composer

$ curl -sS https://getcomposer.org/installer | php

Or if you don't have curl:

$ php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

Add as dependency

$ php composer.phar require hieblmedia/simple-php-encrypter-decrypter:dev-master

After installing, you need to require Composer's autoloader (if not already present):

<?php

require 'vendor/autoload.php';

// ...

Usage

<?php

$value = 'My String';

// Get encrypter with random secure key
$encrypter = new \HieblMedia\Encryption\Encrypter;

$encodedValue = $encrypter->encode($value);
echo "Encoded value: $encodedValue\n"; // Encrypted value

$decodedValue = $encrypter->decode($encodedValue);
echo "Decoded value: $decodedValue\n"; // My String

Use your own fixed secure key

<?php

$encrypter = new \HieblMedia\Encryption\Encrypter('yourFixedSecureKey');

// ...

Tests

You can run the unit tests with the following command:

$ cd path/to/Encrypter/
$ php composer.phar install --dev
$ phpunit