File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -10,19 +10,14 @@ use zip::{
1010} ;
1111
1212fn main ( ) {
13+ let key = "password12345678password12345678" . as_bytes ( ) ;
1314 let encrypted_file_path = "sample-file.txt.encrypted" ;
1415
15- encrypt_file (
16- "sample-file.txt" ,
17- "password12345678password12345678" . as_bytes ( ) ,
18- ) ;
16+ encrypt_file ( "sample-file.txt" , & key) ;
1917
20- decrypt_file (
21- encrypted_file_path,
22- "password12345678password12345678" . as_bytes ( ) ,
23- ) ;
18+ decrypt_file ( encrypted_file_path, & key) ;
2419
25- zip_folder ( "vault" , "vault.zip" ) ;
20+ encrypt_folder ( "vault" , & key ) ;
2621}
2722
2823type Aes256Cbc = Cbc < Aes256 , Pkcs7 > ;
@@ -93,3 +88,10 @@ fn zip_folder(folder_path: &str, output_path: &str) {
9388
9489 zip. finish ( ) . expect ( "Failed to finalize the zip file" ) ;
9590}
91+
92+ fn encrypt_folder ( folder_path : & str , key : & [ u8 ] ) {
93+ let zip_path = format ! ( "{}.zip" , folder_path) ;
94+ zip_folder ( folder_path, & zip_path) ;
95+ encrypt_file ( & zip_path, key) ;
96+ fs:: remove_file ( & zip_path) . expect ( "Failed to remove the intermediate zip file :|" ) ;
97+ }
You can’t perform that action at this time.
0 commit comments