if (!
is_resource($ifp)) { throw new SodiumException('Could not open input file for reading'
);
} /** @var resource $ofp */
$ofp =
fopen($outputFile, 'wb'
);
if (!
is_resource($ofp)) { fclose($ifp);
throw new SodiumException('Could not open output file for writing'
);
} $res = self::
secretbox_encrypt($ifp,
$ofp,
$size,
$nonce,
$key);
fclose($ifp);
fclose($ofp);
return $res;
} /**
* Seal a file (rather than a string). Uses less memory than
* ParagonIE_Sodium_Compat::crypto_secretbox_open(), but produces
* the same result.
*
* Warning: Does not protect against TOCTOU attacks. You should
* just load the file into memory and use crypto_secretbox_open() if
* you are worried about those.
*
* @param string $inputFile
* @param string $outputFile
* @param string $nonce
* @param string $key
* @return bool
* @throws SodiumException
* @throws TypeError
*/