EDIT: Reworked question. Previous version too poorly asked.
On my website users write sensitive messages that must be kept secret. The entire user area is over SSL, so the communication between user and server should be fairly secure. Now I want to store the messages in a secure way, so that an attacker who gets access to the database can't read messages.
With the help of Security.SE, I'm currently implementing this encryption scheme Implementation review - Independent key, admin side and user side .
As you can see, userkey (uk) is something sensitive and it is generated at login time with PBKDF2 (with password and user salt). I can't require the user to input the password every time he wants to read a message, so I want to mantain the uk between requests. What's the best way to prevent that an attacker obtains uk?
I think I can generate uk at login time (when the user inputs the pass), encrypt it and store it.
I know that php sessions aren't so secure, apc_cache_info() could be very damaging, cookies can be stolen. So, IV in a cookie, key in APC cache, cipher in the session: attackers have to get the cookies, disk access, RAM access to decrypt the uk. Am I wrong?
What if I:
- Generate a random key r
- Generate a random initialization vector IV
- Crypt the data (a PBKDF2 key, 100 rounds) with AES 128 CBC and with r as key and IV as IV
- Store the cyphertext in the standard session data
- Store the key in APC cache
- Store the IV in a cookie
- Fetch IV, r, and cipher when I need it, decrypt data and use it
I'd want to know if uk is now stored more securely. Could you suggest better way to do it?
Thanks a lot