function verify(string $key, string $nonce, string $aad, string $ciphertext, string $tag) : bool { $cipher = new Cipher(); $context = $cipher->init($key, $nonce); $cipher->aad($context, $aad); $cipher->verify($context, $ciphertext); try { $cipher->finish($context, $tag); return true; } catch (AuthenticationException $e) { return false; } }