Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
verschuur committed Sep 29, 2016
0 parents commit 497422b
Show file tree
Hide file tree
Showing 10 changed files with 1,559 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage
vendor
.DS_Store
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.0.0] - 2016-09-29
### Added
- Everything for initial release :shipit:
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2016 NoProtocol

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# PHP MySQL AES encrypt/decrypt

Encrypt/decrypt values in PHP which are compatible with MySQL's `aes_encrypt()` & `aes_decrypt()` functions. <sup name="top">[1](#smashing-magazine-article)</sup>

## Installation

### With Composer

```
$ composer require noprotocol/php-mysql-aes-crypt
```

```json
{
"require": {
"noprotocol/php-mysql-aes-crypt": "^1.0.0"
}
}
```

```php
<?php
require 'vendor/autoload.php';

use NoProtocol\Encryption\MySQL\AES\Crypter;
```

<a name="install-nocomposer"/>
### Without Composer

Please use [Composer](http://getcomposer.org/). If you need to install manually, download [Crypter.php](https://github.com/noprotocol/php-mysql-aes-crypt/src/NoProtocol/Encryption/MySQL/AES/Crypter.php) from the repository and save the file into your project path.

```php
<?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
<?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);
```

## 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.

## Testing
PHPunit test cases are provided in `/tests`.

---

<sup id="smashing-magazine-article">1</sup>As outlined in [http://www.smashingmagazine.com/2012/05/replicating-mysql-aes-encryption-methods-with-php/](http://www.smashingmagazine.com/2012/05/replicating-mysql-aes-encryption-methods-with-php/) [](#top)
29 changes: 29 additions & 0 deletions benchmarks/benchmarks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

require './vendor/autoload.php';

use Symfony\Component\Stopwatch\Stopwatch;
use NoProtocol\Encryption\MySQL\AES\Crypter;

set_time_limit(0);

$crypter = new Crypter('mySuperDuperSecretKey');
$stopwatch = new Stopwatch();

$amount = 10000;
if(isset($argv[1]) && is_numeric($argv[1])) {
$amount = $argv[1];
}

echo sprintf('Running benchmark with %s items...', $amount) . PHP_EOL;

$stopwatch->start('encrypt');

for($i = 0; $i < $amount; $i++ ) {
$encrypted = $crypter->encrypt(uniqid('', true));
$decrypted = $crypter->decrypt($encrypted);
}

$event = $stopwatch->stop('encrypt');

echo sprintf('%s items in %s seconds (%s ms), max. memory usage %sKB (%sB)', $amount, $event->getDuration()/1000, $event->getDuration(), $event->getMemory()/1024, $event->getMemory()) . PHP_EOL;
31 changes: 31 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "noprotocol/php-mysql-aes-crypt",
"description": "Encrypt/decrypt data in PHP to a format compatible with MySQL AES_ENCRYPT & AES_DECRYPT functions.",
"keywords": ["php", "mysql", "aes", "encryption", "decryption", "noprotocol"],
"require": {
},
"require-dev": {
"phpunit/phpunit": "5.0.*",
"symfony/stopwatch": "^3.1"
},
"license": "MIT",
"authors": [
{
"name": "Bob Fanger",
"email": "[email protected]"
},
{
"name": "Anne Jan Brouwer",
"email": "[email protected]"
},
{
"name": "Govert Verschuur",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"NoProtocol\\Encryption\\MySQL\\AES\\": "src/"
}
}
}
Loading

0 comments on commit 497422b

Please sign in to comment.