pub fn encrypt_file(
input_path: impl AsRef<Path>,
output_path: impl AsRef<Path>,
key: &[u8],
algorithm: Algorithm,
) -> Result<()>Available on crate features
stream and std only.Expand description
Encrypt the file at input_path into output_path using key and
the given AEAD algorithm. Uses the default chunk size (64 KiB).
The output file is overwritten if it already exists. On any failure after the output file has been opened, callers should treat the output file as junk and remove it.
§Errors
Error::InvalidKeyifkeyis not 32 bytes.Error::RandomFailureif the OS RNG cannot produce a nonce.Error::Macfor I/O failures (file open, read, write) — the variant carries a&'static strreason; the underlyingstd::io::Erroris not surfaced (would risk leaking path fragments through error rendering).Error::AuthenticationFailedfor the (unreachable in practice) AEAD failure path.
§Example
use crypt_io::Algorithm;
use crypt_io::stream;
let key = [0u8; 32];
stream::encrypt_file("input.bin", "output.enc", &key, Algorithm::ChaCha20Poly1305)?;