use aes_gcm::{Aes256Gcm, Nonce, KeyInit};
use aes_gcm::aead::Aead;
pub fn aes_encrypt(key: &[u8; 32], nonce: &[u8; 12], plaintext: &str) -> Result<Vec<u8>, String> {
let cipher = Aes256Gcm::new_from_slice(key)
.map_err(|e| format!("Invalid key: {}", e))?;
let nonce = Nonce::from_slice(nonce);
cipher.encrypt(nonce, plaintext.as_bytes())
.map_err(|e| format!("Encryption failed: {}", e))
}
pub fn aes_decrypt(key: &[u8; 32], nonce: &[u8; 12], ciphertext: &[u8]) -> Result<String, String> {
let cipher = Aes256Gcm::new_from_slice(key)
.map_err(|e| format!("Invalid key: {}", e))?;
let nonce = Nonce::from_slice(nonce);
let decrypted_data = cipher.decrypt(nonce, ciphertext)
.map_err(|e| format!("Decryption failed: {}", e))?;
String::from_utf8(decrypted_data)
.map_err(|e| format!("Invalid UTF-8: {}", e))
}