SERIAL + AES + RF24 (or other wireless device)

HI Guys and Ladies :slight_smile:

I'm new on this forum so please forgive me if i make some mistakes.

I'm trying to build wireless serial connection between two arduinos using NRF24 with external antenna which will give me better range than pcb build antenna or bluetooth.
I used Serial Chat Example for NRF24 and it works perfect but the problem is that (maybe i'm wrong) ctransmission is volunerable for replay attack.

I was thinking to use AES encryption but with ECB mode data can be "replayed" as well, and i try to use RANDOM function for generate AES key but i don' realy know how to sync keys between devices.

Can you give me anu ideas how to protect transmission.

What are you really trying to do?
Why would a "replay attack" be a problem?

i want to wireless communicate between two PC, and it must to be secure due security in house. Htose PC will get controll over curtains, lights, dors, locks...

The most secure connection between two PCs is a cable that is visible everywhere.

Since you are designing the communications protocol, you can do anything you want.

Wireless garage door openers, for example, often employ a "rolling code" that changes with every transmission according to some algorithm. Without knowledge of the algorithm, it is impossible for a hacker to predict the next transmission code from the present one.

yes i know that, also i can use random() to generate new AES key but the problem i have is how to send data separate from serial buffer as is in serial_chat.ino sketch. I'm not too good with parsing data

how to send data separate from serial buffer as is in serial_chat.ino

I have no idea what that sentence means.

i want to use two keys OLD and NEW for UART encryption.
My idea is to generate key on the begining - share between devices, then generate random key and send before UART data as a new key whch is used for incoming data from UART.
Every time UASR recive new data for transmit by NRF24 arduino generate new key and send before send encrypted data.
Also new key is encrypted with previous key which will be overwiten with new key incoming (OLD_KEY = NEW_KEY)

The problem i got is to buffer UART data when they avaliable, then gererate random key and add it to the buffer, encrypt data from UART buffer with new key - add everything to anothe buffer and send, then clear buffers