Expand description

Enc_File

Encrypt / decrypt files or calculate hash from the command line. Warning: This crate hasn’t been audited or reviewed in any sense. I created it to easily encrypt und decrypt non-important files which won’t cause harm if known by third parties. Don’t use for anything important, use VeraCrypt or similar instead.

Breaking change in Version 0.3: Changed input of some functions. To encrypt/decrypt and hash use e.g. “encrypt_chacha(readfile(example.file).unwrap(), key).unwrap()”. Using a keymap to work with several keys conveniently. You can import your old keys, using “Add key” -> “manually”.

Breaking change in Version 0.2: Using XChaCha20Poly1305 as default encryption/decryption. AES is still available using encrypt_aes or decrypt_aes to maintain backwards compability.

Uses XChaCha20Poly1305 (https://docs.rs/chacha20poly1305) or AES-GCM-SIV (https://docs.rs/aes-gcm-siv) for encryption, bincode (https://docs.rs/bincode) for encoding and BLAKE3 (https://docs.rs/blake3) or SHA256 / SHA512 (https://docs.rs/sha2) for hashing.

Encrypted files are (and have to be) stored as .crpt.

Can be used as library and a binary target. Install via cargo install enc_file

Panics at errors making safe execution impossible.

Examples

use enc_file::{encrypt_chacha, decrypt_chacha, read_file};

//Plaintext to encrypt
let text = b"This a test";
//Provide key. Key will normally be chosen from keymap and provided to the encrypt_chacha() function
let key: &str = "an example very very secret key.";
//Convert text to Vec<u8>
let text_vec = text.to_vec();

//Encrypt text
//Ciphertext stores the len() of encrypted content, the nonce and the actual ciphertext using bincode
let ciphertext = encrypt_chacha(text_vec, key).unwrap(); //encrypt vec<u8>, returns result(Vec<u8>)
//let ciphertext = encrypt_chacha(read_file(example.file).unwrap(), key).unwrap(); //read a file as Vec<u8> and then encrypt
//Check that plaintext != ciphertext
assert_ne!(&ciphertext, &text);

//Decrypt ciphertext to plaintext
let plaintext = decrypt_chacha(ciphertext, key).unwrap();
//Check that text == plaintext
assert_eq!(format!("{:?}", text), format!("{:?}", plaintext));
use enc_file::{get_blake3_hash};

let test = b"Calculating the BLAKE3 Hash of this text";
let test_vec = test.to_vec(); //Convert text to Vec<u8>
let hash1 = get_blake3_hash(test_vec.clone()).unwrap();
let hash2 = get_blake3_hash(test_vec).unwrap();
assert_eq!(hash1, hash2); //Make sure hash1 == hash2
let test2 = b"Calculating the BLAKE3 Hash of this text."; //"." added at the end
let test2_vec = test2.to_vec();
let hash3 = get_blake3_hash(test2_vec).unwrap();
assert_ne!(hash1, hash3); //check that the added "." changes the hash and hash1 != hash3

See https://github.com/LazyEmpiricist/enc_file

Functions

Adds key to keymap. Taking a keymap “keymap_plaintext” and user provided password.

Allows user to choose desired hashing function. Returns result.

Creates a new keyfile. User can choose to create a random key or manually enter 32-long char-utf8 password in a keyfile. Key has to be valid utf8. Resturns result (password, keyfile and bool (true if new keyfile way created)).

Decrypts ciphertext (Vec) with a key (&str) using AES256 GCM SIV. Panics with wrong key. Returns result (cleartext as Vec).

Decrypts ciphertext (Vec) with a key (&str) using XChaCha20Poly1305 (24-byte nonce as compared to 12-byte in ChaCha20Poly1305). Panics with wrong key. Returns result (cleartext as Vec).

Decrypts file. Taking a keymap “keymap_plaintext” and the choosen encryption “enc” (“chacha” for ChaCha20Poly1305 or “aes” for AES256-GCM-SIV). Returns result.

Examples

Encrypts cleartext (Vec) with a key (&str) using XChaCha20Poly1305 (24-byte nonce as compared to 12-byte in ChaCha20Poly1305). Returns result (ciphertext as Vec).

Encrypts file. Taking a keymap “keymap_plaintext” and the choosen encryption “enc” (“chacha” for ChaCha20Poly1305 or “aes” for AES256-GCM-SIV). Returns result.

Encrypt a given hashmap with a given password using ChaCha20Poly1305. Returns result (Vec)

Get BLAKE3 Hash from data. File needs to be read as Vec (e.g. use enc_file::read_file()). Returns result. Uses multithreading if len(Vec) > 128.000

Reads userinput from stdin and returns it as String. Returns result.

Get SHA2-256 Hash from data. File needs to be read as Vec (e.g. use enc_file::read_file()). Returns result.

Get SHA2-512 Hash from data. File needs to be read as Vec (e.g. use enc_file::read_file()). Returns result.

Get SHA3-256 Hash from data. File needs to be read as Vec (e.g. use enc_file::read_file()). Returns result.

Get SHA3-512 Hash from data. File needs to be read as Vec (e.g. use enc_file::read_file()). Returns result.

Reads file from same folder as Vec. Returns result.

Read keyfile to keymap. Asks for userpassword. Returns result (password, keymap and bool(false as no new keymap was created))

Removes choosen key from keymap. Taking a keymap “keymap_plaintext” and user provided password.

Saves file to same folder. Returns result