diff options
Diffstat (limited to 'client-native-lib/src/crypto.rs')
-rw-r--r-- | client-native-lib/src/crypto.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/client-native-lib/src/crypto.rs b/client-native-lib/src/crypto.rs index 239c9f3..0472ec7 100644 --- a/client-native-lib/src/crypto.rs +++ b/client-native-lib/src/crypto.rs @@ -7,6 +7,7 @@ use aes_gcm::{ aead::{generic_array::sequence::GenericSequence, Aead}, Aes256Gcm, KeyInit, Nonce, }; +use base64::Engine; use log::info; pub struct Key(Aes256Gcm); @@ -14,7 +15,9 @@ pub struct Key(Aes256Gcm); impl Key { pub fn derive(secret: &str) -> Self { info!("running key generation..."); - let salt = base64::decode("thisisagoodsaltAAAAAAA==").unwrap(); + let salt = base64::engine::general_purpose::STANDARD + .decode("thisisagoodsaltAAAAAAA==") + .unwrap(); let mut key = [0u8; 32]; fastpbkdf2::pbkdf2_hmac_sha256(secret.as_bytes(), salt.as_slice(), 250000, &mut key); @@ -28,10 +31,10 @@ impl Key { let ciphertext = self.0.encrypt(&iv, s.as_bytes()).unwrap(); let mut packet = iv.to_vec(); // TODO this could be doing less allocations packet.extend(ciphertext); - base64::encode(packet) + base64::engine::general_purpose::STANDARD.encode(packet) } pub fn decrypt(&self, s: &str) -> String { - let r = base64::decode(s).unwrap(); + let r = base64::engine::general_purpose::STANDARD.decode(s).unwrap(); let iv = &r[0..12]; let ciphertext = &r[12..]; let plaintext = self.0.decrypt(Nonce::from_slice(iv), ciphertext).unwrap(); |