crypt-config 0.2.2

A crypt module that encrypt/decrypt json data based on the configuration. This might be used as a layer before saving data in Mongo DB or after fetching the data from the DB in order to decrypt them.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use crate::error::CryptResult;
use rand::Rng;

pub fn generate_salt() -> Vec<u8> {
  rand::thread_rng().gen::<[u8; 32]>().to_vec()
}

pub trait ICipher {
  fn encrypt(&self, data: &str) -> CryptResult<Vec<u8>>;
  fn encrypt_with_salt(&self, data: &str, salt: &[u8]) -> CryptResult<Vec<u8>>;
  fn decrypt(&self, data: &[u8]) -> CryptResult<String>;
  fn decrypt_with_salt(&self, data: &[u8], salt: &[u8]) -> CryptResult<String>;

  fn get_salt(&self) -> &Vec<u8>;
}