Two-way encryption (encrypt and decrypt) data using PHP with OpenSSL
PHP
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/OpenCrypt Refactor IV Oct 26, 2017
tests Generate IV and Key safes Oct 24, 2017
.editorconfig
.gitignore
.scrutinizer.yml
.travis.yml Create .travis.yml Oct 24, 2017
LICENSE
README.md
composer.json change description Oct 26, 2017
composer.lock
phpunit.xml

README.md

opencrypt

Build Status Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Latest Unstable Version License composer.lock

Two-way encryption (encrypt and decrypt) data using PHP with OpenSSL

Installation

composer require martinusso/opencrypt

Tips

  • $secretKey should have been previously generated in a cryptographically safe way, like openssl_random_pseudo_bytes. OpenCrypt has a static method OpenCrypt::generateKey() for this.

Usage

$password = "OpenCrypt";

// Should have been previously generated in a cryptographically safe way
$secretKey = 'SECRET_KEY';

// You can pass the IV as argument or it is generated automatically
$openCrypt = new OpenCrypt($secretKey [, string $iv ]);

// get the IV
$iv = $openCrypt->iv();

// encrypt
$encryptedPassword = $openCrypt->encrypt($password);
// $encryptedPassword = 'GWw3bqL7FqjmRs0yyIR/8A=='

// decrypt
$decryptedPassword = $openCrypt->decrypt($encryptedPassword);
// $decryptedPassword = 'OpenCrypt'

generate IV

OpenCrypt offers a static method to generate a safe IV:

$iv = OpenCrypt::generateIV();

generate key

it is also possible to generate a safe secret key:

$secretKey = OpenCrypt::generateKey();

License

This software is open source, licensed under the The MIT License (MIT). See LICENSE for details.