seal() public static method

Encrypt a file using anonymous public-key encryption (with ciphertext authentication).
public static seal ( string | resource $input, string | resource $output, EncryptionPublicKey $publicKey ) : integer
$input string | resource File name or file handle
$output string | resource File name or file handle
$publicKey EncryptionPublicKey Recipient's encryption public key
return integer Number of bytes written
Example #1
0
 public function testSealFail()
 {
     \touch(__DIR__ . '/tmp/paragon_avatar.seal_fail.png');
     \chmod(__DIR__ . '/tmp/paragon_avatar.seal_fail.png', 0777);
     \touch(__DIR__ . '/tmp/paragon_avatar.open_fail.png');
     \chmod(__DIR__ . '/tmp/paragon_avatar.open_fail.png', 0777);
     $keypair = KeyFactory::generateEncryptionKeyPair();
     $secretkey = $keypair->getSecretKey();
     $publickey = $keypair->getPublicKey();
     File::seal(__DIR__ . '/tmp/paragon_avatar.png', __DIR__ . '/tmp/paragon_avatar.seal_fail.png', $publickey);
     $fp = \fopen(__DIR__ . '/tmp/paragon_avatar.seal_fail.png', 'ab');
     \fwrite($fp, \Sodium\randombytes_buf(1));
     fclose($fp);
     try {
         File::unseal(__DIR__ . '/tmp/paragon_avatar.seal_fail.png', __DIR__ . '/tmp/paragon_avatar.opened.png', $secretkey);
         $this->fail('Possible authentication bypass in File::unseal()!');
     } catch (CryptoException\InvalidMessage $e) {
         $this->assertTrue($e instanceof CryptoException\InvalidMessage);
     }
 }