| Total Complexity | 6 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | final class Encryption |
||
| 19 | { |
||
| 20 | /** @var string Default encryption method */ |
||
| 21 | public const DEFAULT_METHOD = 'AES-128-CBC'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Data encryption function. |
||
| 25 | * |
||
| 26 | * @param array $data |
||
| 27 | * |
||
| 28 | * @return string |
||
| 29 | */ |
||
| 30 | public function encrypt(array $data): string |
||
| 31 | { |
||
| 32 | return (new \App\Encryption($this->getConfig()))->encrypt(\App\Json::encode($data), true); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Data decryption function. |
||
| 37 | * |
||
| 38 | * @param string $data |
||
| 39 | * |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | public function decrypt(string $data): array |
||
| 43 | { |
||
| 44 | return \App\Json::decode((new \App\Encryption($this->getConfig()))->decrypt($data, true)) ?: []; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Get default configuration data for encryption. |
||
| 49 | * |
||
| 50 | * @return array |
||
| 51 | */ |
||
| 52 | public function getDefaultData(): array |
||
| 58 | ]; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Configuration data for encryption. |
||
| 63 | * |
||
| 64 | * @return array |
||
| 65 | */ |
||
| 66 | private function getConfig(): array |
||
| 78 |