pub fn decrypt_data(data: Vec<u8>, key: [u8; 32]) -> Result<String> {
    let key = Key::from_slice(&key);
    let cipher = Aes256Gcm::new(key);
    let (nonce_slice, data_slice) = data.split_at(12);
    let nonce = Nonce::from_slice(nonce_slice);
    let encrypted_data = cipher
        .decrypt(nonce, data_slice.as_ref())
        .map_err(|_| Error::Decryption)?;
    String::from_utf8(encrypted_data).map_err(|_| Error::Decryption)
}
/// Decrypts a message with AES-GCM.
/// The first 12 bytes of the message are the nonce.
/// The rest of the message is the ciphertext.
Decrypts a message with AES-GCM.
The first 12 bytes of the message are the nonce.
The rest of the message is the ciphertext.
Decrypts a message with AES - GCM . The first 12 bytes of the message are the nonce . The rest of the message is the ciphertext .
pub fn decrypt_data(data: Vec<u8>, key: [u8; 32]) -> Result<String> {
    let key = Key::from_slice(&key);
    let cipher = Aes256Gcm::new(key);
    let (nonce_slice, data_slice) = data.split_at(12);
    let nonce = Nonce::from_slice(nonce_slice);
    let encrypted_data = cipher
        .decrypt(nonce, data_slice.as_ref())
        .map_err(|_| Error::Decryption)?;
    String::from_utf8(encrypted_data).map_err(|_| Error::Decryption)
}
pub fn decrypt_data ( data : Vec < u8 > , key : [ u8 ; 32 ] ) -> Result < String > { let key = Key :: from_slice ( & key ) ; let cipher = Aes256Gcm :: new ( key ) ; let ( nonce_slice , data_slice ) = data . split_at ( 12 ) ; let nonce = Nonce :: from_slice ( nonce_slice ) ; let encrypted_data = cipher . decrypt ( nonce , data_slice . as_ref ( ) ) . map_err ( | _ | Error :: Decryption ) ? ; String :: from_utf8 ( encrypted_data ) . map_err ( | _ | Error :: Decryption ) }
Decrypts a message with AES-GCM.
Decrypts a message with AES - GCM .
data
Vec<u8>
key
[u8; 32]
data
Vec<u8>
key
[u8; 32]