| Total Complexity | 6 |
| Total Lines | 72 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 6 | class Encrypt |
||
| 7 | { |
||
| 8 | public $data; |
||
| 9 | public $plainText; |
||
| 10 | public $cipher; |
||
| 11 | public $key; |
||
| 12 | public $options; |
||
| 13 | public $iv; |
||
| 14 | public $tag; |
||
| 15 | public $aad; |
||
| 16 | public $tagLength; |
||
| 17 | public $cipherText; |
||
| 18 | protected $flag = 1; |
||
| 19 | |||
| 20 | 9 | public function __construct( |
|
| 21 | $data, |
||
| 22 | $cipher, |
||
| 23 | $key, |
||
| 24 | $options = 0, |
||
| 25 | $iv = null, |
||
| 26 | $tag = null, |
||
| 27 | $aad = '' |
||
| 28 | ) { |
||
| 29 | 9 | if (!in_array($cipher, openssl_get_cipher_methods(), true)) { |
|
| 30 | 3 | throw new \RuntimeException('cipher: ' . $cipher . 'not support'); |
|
| 31 | } |
||
| 32 | 6 | $this->data = $data; |
|
| 33 | 6 | $this->cipher = $cipher; |
|
| 34 | 6 | $this->key = $key; |
|
| 35 | 6 | $this->options = $options; |
|
| 36 | 6 | $ivLen = openssl_cipher_iv_length($cipher); |
|
| 37 | 6 | $this->iv = $iv ?? openssl_random_pseudo_bytes($ivLen); |
|
| 38 | 6 | $this->tag = $tag; |
|
| 39 | 6 | $this->aad = $aad; |
|
| 40 | 6 | $this->tagLength = mb_strlen($this->tag); |
|
| 41 | 6 | } |
|
| 42 | |||
| 43 | 6 | public function encrypt() |
|
| 60 | } |
||
| 61 | |||
| 62 | 6 | public function decrypt() |
|
| 78 | } |
||
| 79 | } |
||
| 80 |