Giter Site home page Giter Site logo

netsan / php-mysql-aes-crypt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from noprotocol/php-mysql-aes-crypt

0.0 1.0 0.0 37 KB

Encrypt/decrypt data in PHP to a format compatible with MySQL AES_ENCRYPT & AES_DECRYPT functions.

License: MIT License

PHP 100.00%

php-mysql-aes-crypt's Introduction

PHP MySQL AES encrypt/decrypt

Encrypt/decrypt values in PHP which are compatible with MySQL's aes_encrypt() & aes_decrypt() functions. 1

Build Status Scrutinizer Code Quality Code Coverage

Change log

Installation

With Composer

$ composer require noprotocol/php-mysql-aes-crypt
{
    "require": {
        "noprotocol/php-mysql-aes-crypt": "^2.0.0"
    }
}
<?php
require 'vendor/autoload.php';

use NoProtocol\Encryption\MySQL\AES\Crypter;

Please use Composer. If you need to install manually, download Crypter.php from the repository and save the file into your project path.

<?php
require 'path/to/Cryper.php';

use NoProtocol\Encryption\MySQL\AES\Crypter;

Usage

Create a new instance of the class with a string which will be used as the key for the crypting process. Run encrypt() or decrypt() to encrypt/decrypt your data.

<?php
use NoProtocol\Encryption\MySQL\AES\Crypter;

// create a new instance
$crypter = new Crypter('mykeystring');

// encrypt a piece of data
$encrypted = $crypter->encrypt('foobar');

// decrypt a piece of data
$decrypted = $crypter->decrypt($encrypted);

Using a different encryption method is possible too when so desired.

$crypter = new Crypter('mykeystring', 'AES-256-ECB');

NB: This is only tested for AES-128-ECB (default), AES-192-ECB and AES-256-ECB

Benchmark

A benchmark is provided in /benchmarks/benchmarks.php. You can set the number of items to run by passing a number as an argument, e.g.:

php benchmarks/benchmarks.php 20000

to run 20000 items. If no number is given, it defaults to 10000 items.

You can also optionally set the desired encryption method for example:

php benchmarks/benchmarks.php 20000 AES-256-ECB

Testing

PHPunit test cases are provided in /tests.


1As outlined in http://www.smashingmagazine.com/2012/05/replicating-mysql-aes-encryption-methods-with-php/ โ†ฉ

php-mysql-aes-crypt's People

Contributors

annejan avatar scrutinizer-auto-fixer avatar verschuur avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.