[−][src]Function enc_file::encrypt_hashmap
pub fn encrypt_hashmap(
keymap_plaintext: HashMap<String, String>,
password: &String
) -> Result<Vec<u8>, Box<dyn Error>>
Encrypt a given hashmap with a given password using ChaCha20Poly1305. Returns result (Vec
Examples
use std::collections::HashMap; use aes_gcm_siv::aead::{generic_array::GenericArray, Aead, NewAead}; use chacha20poly1305::XChaCha20Poly1305; use enc_file::{encrypt_hashmap}; use serde::{Deserialize, Serialize}; //create example keymap. Keymap constits of key-name and actual-key. Attention: Valid keys for cryptography needs to be 32-chars utf8! let mut keymap_plaintext: HashMap<String, String> = HashMap::new(); keymap_plaintext.insert("Hello".to_string(), "world".to_string()); //create (extremely insecure) password let password: String = "Password".to_string(); //encrypt keymap with password let encrypted: Vec<u8> = encrypt_hashmap(keymap_plaintext.clone(), &password).unwrap(); //test that encrypting 2 times results in different Vec<u8> let encrypted2: Vec<u8> = encrypt_hashmap(keymap_plaintext, &password).unwrap(); assert_ne!(encrypted, encrypted2);