| Total Complexity | 4 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class SecretBox extends CryptoBox{ |
||
| 16 | |||
| 17 | public function create(string $message, string $nonce_bin = null):CryptoBoxInterface{ |
||
| 18 | $this->checkKeypair(SODIUM_CRYPTO_BOX_SECRETKEYBYTES); |
||
| 19 | |||
| 20 | $message = $this->checkMessage($message); |
||
| 21 | $this->nonce = $nonce_bin ?? random_bytes(SODIUM_CRYPTO_BOX_NONCEBYTES); |
||
| 22 | $this->box = sodium_crypto_secretbox($message, $this->nonce, $this->keypair->secret); |
||
|
|
|||
| 23 | |||
| 24 | sodium_memzero($message); |
||
| 25 | |||
| 26 | if($nonce_bin !== null){ |
||
| 27 | sodium_memzero($nonce_bin); |
||
| 28 | } |
||
| 29 | |||
| 30 | return $this; |
||
| 31 | } |
||
| 32 | |||
| 33 | public function open(string $box_bin, string $nonce_bin):CryptoBoxInterface{ |
||
| 43 | } |
||
| 44 | |||
| 46 |