1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use dbui_core::{Error, Result};
use short_crypt::ShortCrypt;
pub(crate) fn decrypt(key: &str, enc: &str) -> Result<String> {
let sc = ShortCrypt::new(key);
let dec = sc
.decrypt_url_component(enc)
.map_err(|e| Error::from(format!("Error encrypting text: {}", e)))?;
std::str::from_utf8(&dec)
.map_err(|e| Error::from(format!("Error creating utf-8 text: {}", e)))
.map(|v| v.into())
}
pub fn encrypt(key: &str, unenc: &str) -> String {
let sc = ShortCrypt::new(key);
sc.encrypt_to_url_component(unenc)
}