@@ -110,7 +110,6 @@ |
||
| 110 | 110 | /** |
| 111 | 111 | * Generate a new key that meets requirements for dcrypt |
| 112 | 112 | * |
| 113 | - * @param int $size Size of key in bytes |
|
| 114 | 113 | * @return string |
| 115 | 114 | * @throws InvalidKeyException |
| 116 | 115 | */ |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function authenticationKey(string $info): string |
| 82 | 82 | {
|
| 83 | - return $this->deriveKey(__FUNCTION__ . '|' . $info); |
|
| 83 | + return $this->deriveKey(__FUNCTION__.'|'.$info); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function encryptionKey(string $info): string |
| 93 | 93 | {
|
| 94 | - return $this->deriveKey(__FUNCTION__ . '|' . $info); |
|
| 94 | + return $this->deriveKey(__FUNCTION__.'|'.$info); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -25,8 +25,8 @@ discard block |
||
| 25 | 25 | * @license http://opensource.org/licenses/MIT The MIT License (MIT) |
| 26 | 26 | * @link https://github.com/mmeyer2k/dcrypt |
| 27 | 27 | */ |
| 28 | -final class OpensslKey |
|
| 29 | -{
|
|
| 28 | +final class OpensslKey |
|
| 29 | +{ |
|
| 30 | 30 | /** |
| 31 | 31 | * @var string |
| 32 | 32 | */ |
@@ -50,18 +50,18 @@ discard block |
||
| 50 | 50 | * @param string $ivr Initialization vactor |
| 51 | 51 | * @throws InvalidKeyException |
| 52 | 52 | */ |
| 53 | - public function __construct(string $algo, string $key, string $ivr) |
|
| 54 | - {
|
|
| 53 | + public function __construct(string $algo, string $key, string $ivr) |
|
| 54 | + { |
|
| 55 | 55 | // Store the key as what was supplied |
| 56 | 56 | $this->key = \base64_decode($key); |
| 57 | 57 | |
| 58 | 58 | // Make sure key was properly decoded and meets minimum required length |
| 59 | - if (!is_string($this->key) || Str::strlen($this->key) < 2048) {
|
|
| 59 | + if (!is_string($this->key) || Str::strlen($this->key) < 2048) { |
|
| 60 | 60 | throw new InvalidKeyException("Key must be at least 256 bytes and base64 encoded.");
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Make sure key meets minimum entropy requirement |
| 64 | - if (\count(\array_unique(\str_split($this->key))) < 250) {
|
|
| 64 | + if (\count(\array_unique(\str_split($this->key))) < 250) { |
|
| 65 | 65 | throw new InvalidKeyException("Key does not contain the minimum amount of entropy.");
|
| 66 | 66 | } |
| 67 | 67 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | public static function create(int $bytes = 2048): string |
| 118 | 118 | {
|
| 119 | - if ($bytes < 2048) {
|
|
| 119 | + if ($bytes < 2048) { |
|
| 120 | 120 | throw new InvalidKeyException('Keys must be at least 2048 bytes long.');
|
| 121 | 121 | } |
| 122 | 122 | |
@@ -103,6 +103,6 @@ |
||
| 103 | 103 | $chk = \hash_hmac($algo, $msg, $key->authenticationKey($cipher), true); |
| 104 | 104 | |
| 105 | 105 | // Return iv + checksum + tag + ciphertext |
| 106 | - return $ivr . $chk . $tag . $msg; |
|
| 106 | + return $ivr.$chk.$tag.$msg; |
|
| 107 | 107 | } |
| 108 | 108 | } |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | $key = new OpensslKey($algo, $key, ''); |
| 44 | 44 | |
| 45 | 45 | foreach ($chunks as $i => &$chunk) { |
| 46 | - $info = $length . $i; |
|
| 46 | + $info = $length.$i; |
|
| 47 | 47 | $chunk = $chunk ^ $key->deriveKey($info); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -2,8 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Dcrypt\Examples; |
| 4 | 4 | |
| 5 | -class Aes256Base64 extends \Dcrypt\Aes256Gcm |
|
| 6 | -{
|
|
| 5 | +class Aes256Base64 extends \Dcrypt\Aes256Gcm |
|
| 6 | +{ |
|
| 7 | 7 | public static function decrypt(string $data, string $key): string |
| 8 | 8 | {
|
| 9 | 9 | return parent::decrypt(\base64_decode($data), $key); |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * Displays supported ciphers and algos |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -require __DIR__ . '/../vendor/autoload.php'; |
|
| 11 | +require __DIR__.'/../vendor/autoload.php'; |
|
| 12 | 12 | |
| 13 | 13 | $key = \Dcrypt\OpensslKey::create(); |
| 14 | 14 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | $d = \Dcrypt\OpensslStatic::decrypt($e, $key, $meth, 'sha256'); |
| 28 | 28 | |
| 29 | 29 | echo " [pass] "; |
| 30 | - } catch (\Exception|\Error $e) { |
|
| 30 | + } catch (\Exception | \Error $e) { |
|
| 31 | 31 | $m = $e->getMessage(); |
| 32 | 32 | echo " [fail] [!!!]"; |
| 33 | 33 | } finally { |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $d = \Dcrypt\OpensslStatic::decrypt($e, $key, 'aes-256-gcm', $algo); |
| 51 | 51 | |
| 52 | 52 | echo " [pass] "; |
| 53 | - } catch (\Exception|\Error $e) { |
|
| 53 | + } catch (\Exception | \Error $e) { |
|
| 54 | 54 | $m = $e->getMessage(); |
| 55 | 55 | echo " [fail] [!!!]"; |
| 56 | 56 | } finally { |
@@ -6,11 +6,11 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | use \Dcrypt\OpensslStatic; |
| 8 | 8 | |
| 9 | -require __DIR__ . '/../vendor/autoload.php'; |
|
| 9 | +require __DIR__.'/../vendor/autoload.php'; |
|
| 10 | 10 | |
| 11 | 11 | $key = \Dcrypt\OpensslKey::create(); |
| 12 | 12 | |
| 13 | -file_put_contents(__DIR__ . '/../tests/vectors/.testkey', $key); |
|
| 13 | +file_put_contents(__DIR__.'/../tests/vectors/.testkey', $key); |
|
| 14 | 14 | |
| 15 | 15 | $out = [ |
| 16 | 16 | 'key' => $key, |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | try {
|
| 29 | 29 | $out['ciphers'][$cipher] = base64_encode(OpensslStatic::encrypt('a secret', $key, $cipher, 'sha3-256'));
|
| 30 | - } catch (\Exception|\Error $e) {
|
|
| 30 | + } catch (\Exception | \Error $e) {
|
|
| 31 | 31 | |
| 32 | 32 | } |
| 33 | 33 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | $out['algos'][$algo] = base64_encode(OpensslStatic::encrypt('a secret', $key, 'aes-256-gcm', $algo));
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | -foreach(['Gcm', 'Ctr', 'Ofb', 'Cbc', 'Ecb'] as $mode){
|
|
| 43 | +foreach (['Gcm', 'Ctr', 'Ofb', 'Cbc', 'Ecb'] as $mode) {
|
|
| 44 | 44 | $c = "\\Dcrypt\\Aes256$mode"; |
| 45 | 45 | $out['aes256'][$c] = base64_encode($c::encrypt('a secret', $key));
|
| 46 | 46 | } |
@@ -51,4 +51,4 @@ discard block |
||
| 51 | 51 | $out['otp'][$mult] = \base64_encode(\Dcrypt\OneTimePad::crypt(str_repeat('A', $mult), $key));
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | -file_put_contents(__DIR__ . '/../tests/.vectors.json', \json_encode($out, JSON_PRETTY_PRINT)); |
|
| 55 | 54 | \ No newline at end of file |
| 55 | +file_put_contents(__DIR__.'/../tests/.vectors.json', \json_encode($out, JSON_PRETTY_PRINT)); |
|
| 56 | 56 | \ No newline at end of file |