I'm using the following article as reference : Example of AES using Crypto++ to implement AES-256 for end-to-end encryption over communication channel (MQTT) with a micro-controller (constrained device).
I'm developing the server/controller in C++ that may be deployed either on Linux or windows machine. Messages between micro-controller and C++ service are exchanged at random interval (15 sec. to 15 min.) depending user activity on the hardware terminal (average interval is about 30-45 seconds) in a particular session.
CryptoPP::AES::Encryption aesEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption( aesEncryption, iv );
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink( ciphertext ) );
stfEncryptor.Put( reinterpret_cast<const unsigned char*>( plaintext.c_str() ), plaintext.length() );
stfEncryptor.MessageEnd();
I wish to know what is the recommended practice should I re-initialize (re-create the object) aesEncryption
and cbcEncryption
for each message or can I reuse them over the session.
I also wish how frequently should I change my IV and encryption/decryption key. Does changing the IV affect encryption/decryption?
Development Platform : x64-linux or x64-windows
Compiler : g++ 9.3.0 or VC++ 16.5.0