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.


Question: What is the white sauce of Domino's pasta made of?
Answer: It's Alfredo sauce and according to Domino's nutrition guide it's made of:


  Water
  Cream (Cream, Milk)
  Parmesan Cheese (Part-Skim Milk, Cheese Cultures, Salt, Enzymes)
  Asiago Cheese (Pasteurized
  Milk, Cheese Culture, Salt, Enzymes)
  Margarine (Palm Oil, Water, Salt, Vegetable Monoglycerides, Whey Solids,Sodium
  Benzoate [Preservative], Natural And Artificial Flavor, Citric Acid, Beta Carotene [Color], Vitamin A Palmitate Added)
  Seasoning
  (Maltodextrin, Nonfat Milk, Modified Corn Starch, Salt, Enriched Bleached Wheat Flour [Bleached Wheat Flour, Malted Barley
  Flour, Niacin, Reduced Iron, Thiamine Mononitrate, Riboflavin, Folic Acid], Disodium Inosinate, Disodium Guanylate, Xanthan
  Gum, Spices, Mono And Diglycerides)
  Butter (Butter, Salt)
  Parmesan Cheese Concentrate (Parmesan Cheese [Pasteurized
  Milk, Cultures, Salt, Enzymes], Water, Salt, Natural Flavors, Yeast Extract, Sodium Phosphates, Sodium Citrate)
  Modified Corn Starch
  Garlic (Garlic, Water)
  Chicken Base (Chicken Meat, Chicken Juices, Salt, Potato Flour, Flavorings, Sugar, Disodium
  Inosinate, Disodium Guanylate)
  Parsley
  Salt


You can definitely make something similar at home. You should also be able to buy something like it in a jar at your local grocery store.