New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

adbario/php-encrypter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adbario/php-encrypter

Encryption with AES-256 and HMAC-SHA256

Source
Packagist
Version
1.0.0
Version published
Total downloads
7.7K
Maintainers
1
Created
Source

PHP Encrypter

This project encrypts and decrypts the given value. It uses OpenSSL extension with AES-256 cipher for encryption and HMAC-SHA-256 for hash. The encryption and hash can use different keys.

PHP Encrypter requires PHP 5.3 or higher, OpenSSL and Multibyte String extensions.

Installation

With Composer:

composer require adbario/php-encrypter

Manual installation:

  • Download the latest release
  • Extract the files into your project
  • Require "/path/to/php-encrypter/src/Encrypter.php";
  • If your PHP version is lower than 7, also polyfill for random_bytes() is required

Usage

Setup the encryption key:

$key = '+NeXrQhAEhW}g8gf^y)Up8hAUKpue7wb';

Change the key to your own custom random 32 character string.

Create a new encrypter instance:

$encrypter = new \Adbar\Encrypter($key);

If you wish to use different key for hashing, you can pass it to constructor as a second parameter:

$encrypter = new \Adbar\Encrypter($key, $authKey);

Encryption

Encrypt a string:

$string = 'This is my string to encrypt.';
$encrypted = $encrypter->encryptString($string);

Encrypt other variable types:

$array = array('key' => 'value');
$encrypted = $encrypter->encrypt($array);

Decryption

Decrypt a string:

$string = $encrypter->decryptString($encrypted);

Decrypt other variable types:

$array = $encrypter->decrypt($encrypted);

License

MIT license

Keywords

security

FAQs

Package last updated on 26 Mar 2017

Related posts