I am planning to use AES encryption in GCM mode for protecting data at rest for my application.
I went through the NIST recommendations for GCM mode. It mentions that the uniqueness of IV is very important. It says that if the (key, IV) pair is repeated, an adversary can construct cipher-text forgery.
Now the design of the application is such that whenever the user accesses data, the entire database is decrypted and loaded into the memory. On closing the application, the data is encrypted and persisted into the db.
What are the best ways of generating and handling IVs in this scenario?
You will need a new NONCE each time you encrypt, you should not encrypt with the same NONCE even if is the same field. It’s best to start each encryption with a fresh, randomly generated IV and prepend this random to the ciphertext. If you don’t you are likely to leak data, even the entire plain text.