-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Florent Morselli
committed
Mar 3, 2016
1 parent
d044a7f
commit 7ba68af
Showing
6 changed files
with
169 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2016 Spomky-Labs | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace AESKW; | ||
|
||
interface EncryptorInterface | ||
{ | ||
/** | ||
* @param string $data | ||
* | ||
* @return string | ||
*/ | ||
public function encrypt($data); | ||
|
||
/** | ||
* @param string $data | ||
* | ||
* @return string | ||
*/ | ||
public function decrypt( $data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2016 Spomky-Labs | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace AESKW; | ||
|
||
final class MCryptEncryptor implements EncryptorInterface | ||
{ | ||
private $kek; | ||
|
||
public function __construct($kek) | ||
{ | ||
$this->kek = $kek; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function encrypt($data) | ||
{ | ||
return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->kek, $data, MCRYPT_MODE_ECB); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function decrypt($data) | ||
{ | ||
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->kek, $data, MCRYPT_MODE_ECB); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2016 Spomky-Labs | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace AESKW; | ||
|
||
final class OpenSSLEncryptor implements EncryptorInterface | ||
{ | ||
private $kek; | ||
private $method; | ||
|
||
public function __construct($kek) | ||
{ | ||
$this->kek = $kek; | ||
$this->method = 'aes-'.(strlen($kek)*8).'-ecb'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function encrypt($data) | ||
{ | ||
return openssl_encrypt($data, $this->method, $this->kek, OPENSSL_ZERO_PADDING|OPENSSL_RAW_DATA); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function decrypt($data) | ||
{ | ||
return openssl_decrypt($data, $this->method, $this->kek, OPENSSL_ZERO_PADDING|OPENSSL_RAW_DATA); | ||
} | ||
} |