| 1 | <?php |
||
| 7 | abstract class EncryptedValue implements JsonSerializable, Serializable |
||
| 8 | { |
||
| 9 | /** @var string */ |
||
| 10 | private $cipherText; |
||
| 11 | /** @var string */ |
||
| 12 | private $method; |
||
| 13 | /** @var string */ |
||
| 14 | private $initializationVector; |
||
| 15 | |||
| 16 | 228 | public function __construct($cipherText, $method, $iv) |
|
| 17 | { |
||
| 18 | 228 | $this->cipherText = $cipherText; |
|
| 19 | 228 | $this->method = $method; |
|
| 20 | 228 | $this->initializationVector = $iv; |
|
| 21 | 228 | } |
|
| 22 | |||
| 23 | 6 | public function jsonSerialize() |
|
| 24 | { |
||
| 25 | return [ |
||
| 26 | 6 | 'cipherText' => $this->cipherText, |
|
| 27 | 6 | 'method' => $this->method, |
|
| 28 | 6 | 'iv' => base64_encode($this->initializationVector), |
|
| 29 | 6 | ]; |
|
| 30 | } |
||
| 31 | |||
| 32 | 6 | public function serialize() |
|
| 36 | |||
| 37 | 6 | public function unserialize($serialized) |
|
| 38 | { |
||
| 39 | 6 | $data = json_decode($serialized); |
|
| 40 | |||
| 41 | 6 | $this->cipherText = $data->cipherText; |
|
| 42 | 6 | $this->method = $data->method; |
|
| 43 | 6 | $this->initializationVector = base64_decode($data->iv); |
|
| 44 | 6 | } |
|
| 45 | |||
| 46 | /** |
||
| 47 | * @return string |
||
| 48 | */ |
||
| 49 | 186 | public function getCipherText() |
|
| 53 | |||
| 54 | /** |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | 132 | public function getMethod() |
|
| 61 | |||
| 62 | /** |
||
| 63 | * @return string |
||
| 64 | */ |
||
| 65 | 132 | public function getInitializationVector() |
|
| 69 | } |
||
| 70 |