public function testSealFail()
{
$alice = KeyPair::generate();
$message = 'This is for your eyes only';
$sealed = Asymmetric::seal($message, $alice->getPublicKey(), true);
// Let's flip one bit, randomly:
$r = \Sodium\randombytes_uniform(\mb_strlen($sealed, '8bit'));
$amt = 1 << \Sodium\randombytes_uniform(8);
$sealed[$r] = \chr(\ord($sealed[$r]) ^ $amt);
// This should throw an exception
try {
$opened = Asymmetric::unseal($sealed, $alice->getSecretKey(), true);
$this->assertEquals($opened, $message);
throw new Exception('ERROR: THIS SHOULD ALWAYS FAIL');
} catch (CryptoException\InvalidKey $e) {
$this->assertTrue($e instanceof CryptoException\InvalidKey);
} catch (CryptoException\InvalidMessage $e) {
$this->assertTrue($e instanceof CryptoException\InvalidMessage);
}
}