-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JWT, Binary, Hexa and Validator bugs fixing
- Loading branch information
Steeven Andrian
committed
Mar 2, 2020
1 parent
3ec9264
commit 7ef5629
Showing
5 changed files
with
137 additions
and
131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ class Binary | |
* @var array | ||
*/ | ||
private static $charactersMap = []; | ||
|
||
/** | ||
* Binary::$crypt | ||
* | ||
|
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,106 @@ | ||
<?php | ||
/** | ||
* This file is part of the O2System Framework package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author Steeve Andrian Salim | ||
* @copyright Copyright (c) Steeve Andrian Salim | ||
*/ | ||
|
||
// ------------------------------------------------------------------------ | ||
|
||
namespace O2System\Security\Encryptions; | ||
|
||
// ------------------------------------------------------------------------ | ||
|
||
/** | ||
* Class Hexadecimal | ||
* @package O2System\Security\Encryptions | ||
*/ | ||
class Hexadecimal | ||
{ | ||
/** | ||
* Binary::$crypt | ||
* | ||
* Crypt instance. | ||
* | ||
* @var Crypt | ||
*/ | ||
private $crypt; | ||
|
||
// ------------------------------------------------------------------------ | ||
|
||
/** | ||
* Binary::__construct | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->crypt = new Crypt(); | ||
} | ||
|
||
// ------------------------------------------------------------------------ | ||
|
||
/** | ||
* Hexadecimal::encrypt | ||
* | ||
* Encrypt string into numbers. | ||
* | ||
* @param string $string String to be encrypted. | ||
* | ||
* @return string | ||
*/ | ||
public function encrypt($string) | ||
{ | ||
$dec = []; | ||
$hex = str_split($this->crypt->encrypt($string), 4); | ||
|
||
foreach ($hex as $char) { | ||
$dec[] = str_pad(hexdec($char), 5, '0', STR_PAD_LEFT); | ||
} | ||
|
||
return implode('', $dec); | ||
} | ||
|
||
// ------------------------------------------------------------------------ | ||
|
||
/** | ||
* Hexadecimal::decrypt | ||
* | ||
* Decrypt numbers. | ||
* | ||
* @param string $string String to be decrypted. | ||
* | ||
* @return string | ||
*/ | ||
public function decrypt($string) | ||
{ | ||
$hex = []; | ||
$dec = str_split($string, 5); | ||
|
||
foreach ($dec as $char) { | ||
$hex[] = str_pad(dechex($char), 4, '0', STR_PAD_LEFT); | ||
} | ||
|
||
return implode('', $hex); | ||
} | ||
|
||
// ------------------------------------------------------------------------ | ||
|
||
/** | ||
* Hexadecimal::setKey | ||
* | ||
* Sets numeric encryption protection key. | ||
* | ||
* @param string $key Custom encryption key. | ||
* | ||
* @return static | ||
*/ | ||
public function setKey($key) | ||
{ | ||
$this->crypt->setKey($key); | ||
|
||
return $this; | ||
} | ||
} |
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