Skip to content

Instantly share code, notes, and snippets.

@xxiz
Created January 2, 2023 20:10
Show Gist options
  • Save xxiz/fb8c92af35136609fd6a9c073d683e50 to your computer and use it in GitHub Desktop.
Save xxiz/fb8c92af35136609fd6a9c073d683e50 to your computer and use it in GitHub Desktop.
file encryptiong using age library v0.9.0
let password = SecretString::new(passphrase.to_string());
let mut file = fs::File::open(file_path).unwrap();
let encryptor = Encryptor::with_user_passphrase(password);
let encryted_file = Path::new(file_path).with_extension("bin");
let output_file = fs::File::create(encryted_file).unwrap();
let mut output = encryptor.wrap_output(output_file).unwrap();
io::copy(&mut file, &mut output).unwrap();
output.finish().unwrap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment