| Total Complexity | 5 |
| Total Lines | 74 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 12 | class AesEncrypter implements EncrypterInterface |
||
| 13 | { |
||
| 14 | public const CYPHER_METHOD = 'aes-256-cbc'; |
||
| 15 | public const INIT_VECTOR_SEPARATOR = ':::'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var \SprykerEco\Zed\Heidelpay\HeidelpayConfig |
||
| 19 | */ |
||
| 20 | protected $config; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param \SprykerEco\Zed\Heidelpay\HeidelpayConfig $config |
||
| 24 | */ |
||
| 25 | public function __construct(HeidelpayConfig $config) |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param string $data |
||
| 32 | * |
||
| 33 | * @return string |
||
| 34 | */ |
||
| 35 | public function encryptData(string $data): string |
||
| 36 | { |
||
| 37 | $encryptionKey = $this->config |
||
| 38 | ->getEncryptionKey(); |
||
| 39 | $initVector = $this->getRandomPseudoBytes(); |
||
| 40 | |||
| 41 | $encryptedData = openssl_encrypt( |
||
| 42 | $data, |
||
| 43 | static::CYPHER_METHOD, |
||
| 44 | $encryptionKey, |
||
| 45 | OPENSSL_RAW_DATA, |
||
| 46 | $initVector |
||
| 47 | ); |
||
| 48 | |||
| 49 | return implode(static::INIT_VECTOR_SEPARATOR, [$encryptedData, base64_encode($initVector)]); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param string $data |
||
| 54 | * |
||
| 55 | * @return string|null |
||
| 56 | */ |
||
| 57 | public function decryptData(string $data) |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @return string |
||
| 80 | */ |
||
| 81 | protected function getRandomPseudoBytes(): string |
||
| 88 |