pub fn encrypt_data(data: &str, key: [u8; 32]) -> Result<Vec<u8>> {
    let key = Key::from_slice(&key);
    let cipher = Aes256Gcm::new(key);
    let nonce_array: [u8; 12] = rand::random();
    let nonce = &Nonce::from(nonce_array);
    let mut encrypted_data = cipher
        .encrypt(nonce, data.as_ref())
        .map_err(|_| Error::Encryption)?;
    let mut final_vec = nonce_array.to_vec();
    final_vec.append(&mut encrypted_data);
    Ok(final_vec)
}
/// Encrypts a message with AES-GCM.
/// The first 12 bytes of the message are the nonce.
/// The rest of the message is the plaintext.
Encrypts a message with AES-GCM.
The first 12 bytes of the message are the nonce.
The rest of the message is the plaintext.
Encrypts a message with AES - GCM . The first 12 bytes of the message are the nonce . The rest of the message is the plaintext .
pub fn encrypt_data(data: &str, key: [u8; 32]) -> Result<Vec<u8>> {
    let key = Key::from_slice(&key);
    let cipher = Aes256Gcm::new(key);
    let nonce_array: [u8; 12] = rand::random();
    let nonce = &Nonce::from(nonce_array);
    let mut encrypted_data = cipher
        .encrypt(nonce, data.as_ref())
        .map_err(|_| Error::Encryption)?;
    let mut final_vec = nonce_array.to_vec();
    final_vec.append(&mut encrypted_data);
    Ok(final_vec)
}
pub fn encrypt_data ( data : & str , key : [ u8 ; 32 ] ) -> Result < Vec < u8 > > { let key = Key :: from_slice ( & key ) ; let cipher = Aes256Gcm :: new ( key ) ; let nonce_array : [ u8 ; 12 ] = rand :: random ( ) ; let nonce = & Nonce :: from ( nonce_array ) ; let mut encrypted_data = cipher . encrypt ( nonce , data . as_ref ( ) ) . map_err ( | _ | Error :: Encryption ) ? ; let mut final_vec = nonce_array . to_vec ( ) ; final_vec . append ( & mut encrypted_data ) ; Ok ( final_vec ) }
Encrypts a message with AES-GCM.
Encrypts a message with AES - GCM .
data
&str
key
[u8; 32]
data
&str
key
[u8; 32]