diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 6a71f79c..207a0ce6 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -26,7 +26,6 @@ rocket = { version = "0.5.1", features = ["json", "tls"] } rand = "0.9.1" rand_chacha = "0.9" base64 = "0.22.1" -cipher = { version = "0.4.4", features = ["std"] } aes = "0.8.4" cbc = "0.1.2" pbkdf2 = "0.12.2" diff --git a/runtime/src/encryption.rs b/runtime/src/encryption.rs index 632915d7..dc9d2ef8 100644 --- a/runtime/src/encryption.rs +++ b/runtime/src/encryption.rs @@ -98,9 +98,14 @@ impl Encryption { /// Encrypts the given data. pub fn encrypt(&self, data: &str) -> Result { let cipher = Aes256CbcEnc::new(&self.key.into(), &self.iv.into()); - let encrypted = cipher.encrypt_padded_vec_mut::(data.as_bytes()); + let data = data.as_bytes(); + let mut buffer = vec![0u8; data.len() + 16]; + buffer[..data.len()].copy_from_slice(data); + let encrypted = cipher + .encrypt_padded_mut::(&mut buffer, data.len()) + .map_err(|e| format!("Error encrypting data: {e}"))?; let mut result = BASE64_STANDARD.encode(self.secret_key_salt); - result.push_str(&BASE64_STANDARD.encode(&encrypted)); + result.push_str(&BASE64_STANDARD.encode(encrypted)); Ok(EncryptedText::new(result)) } @@ -118,9 +123,12 @@ impl Encryption { } let cipher = Aes256CbcDec::new(&self.key.into(), &self.iv.into()); - let decrypted = cipher.decrypt_padded_vec_mut::(encrypted).map_err(|e| format!("Error decrypting data: {e}"))?; + let mut buffer = encrypted.to_vec(); + let decrypted = cipher + .decrypt_padded_mut::(&mut buffer) + .map_err(|e| format!("Error decrypting data: {e}"))?; - String::from_utf8(decrypted).map_err(|e| format!("Error converting decrypted data to string: {}", e)) + String::from_utf8(decrypted.to_vec()).map_err(|e| format!("Error converting decrypted data to string: {}", e)) } }