Every window message (WM_CREATE, WM_DESTROY, WM_PAINT, WM_USER, etc, etc) is sent by something. Most message are sent by Windows in response to some user interaction or some API call. Others are sent by 3rd-party code (for example, when you call the Win32 API SendMessage, it's the caller of SendMessage that is directly sending the message). In any case, the sender of the message probably expects something in response. The expected response depends on the sender of the message and the message type.

In most cases, you'll probably want to follow the rules defined by Microsoft for the window message. For example, in the documentation for WM_CREATE, it says:


  If an application processes this message, it should return zero to continue creation of the window. If the application returns –1, the window is destroyed and the CreateWindowEx or CreateWindow function returns a NULL handle.


When handling WM_CREATE messages, you should return the appropriate value as defined above. When handling other messages, you should return whatever the documentation says about that message. When handing a 3rd-party message such as WM_USER, the 3rd-party should clearly indicate what it expects.

What does the Result property of a windows message mean and when and how to use it?
I'm looking for an efficient way to encrypt multiple fields in a database with AES using a single global key, used throughout a large web application.

Obviously in order to re-use this key, a unique random IV is required for each field that is to be encrypted.

I'd rather not introduce more fields to the database to store each of these IVs, so the programatic approach seems to be to derive these IVs some how.

I'm toying with using either:

key = sha256(global_key + table_name)
iv = sha256(column_name + primary_key)


Or even simply:

key = global_key
iv = sha256(table_name + column_name + primary_key)


I'm leaning towards the former to generate per-table keys.

I've already read that the IVs do not need to be kept secret. So I'm working on the assumption that a derived key or IV (even if the algorithm becomes known), is no more insecure than any other non-secret IV, as long as the original key remains secret.

The question is:

Is there a fatal flaw in my approach? Am I introducing any serious weaknesses that, in the event that an adversary obtains a copy of the database, would make it easier for them to retrieve the plaintext data?

I realise that is potentially soliciting one word answers.

Suggestions for alternate / better schemes very much welcomed, as well as references to existing works and how they implement similar scenarios.
