Encrypt a File with a Password in Rust
Overview
-
This encrypts a file with a password.
-
It's the prototype for the process I'm using to encrypt files for my site that I want to protect with a password. They are served statically then decrypted with /rust/wasm/decrypt-files-for-static-sites/.
-
I'm not protecting anything valuable. It's just a way for me to section off some data on my site. Check with a security expert before working off this if you have higher security needs.
The Files
src/main.rs
use Result;
use ;
use fs;
use PathBuf;
Cargo.toml
[package]
name = "encrypt-a-file-with-a-password"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow = "1.0.102"
orion = "0.17.13"References
-
https://docs.rs/orion/latest/orion/
-
https://docs.rs/orion/latest/orion/aead/index.html
-
https://docs.rs/orion/latest/orion/kdf/index.html
-
https://docs.rs/orion/latest/orion/kdf/struct.Salt.html
-
https://docs.rs/wasm-bindgen/latest/wasm_bindgen/
-
https://doc.libsodium.org/password_hashing/default_phf#guidelines-for-choosing-the-parameters
-
https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html