title: Cryptography: best practices for keys in memory?
body: <p>Background:
  I got some data encrypted with AES (ie symmetric crypto) in a database. A server side application, running on a (assumed) secure and isolated Linux box, uses this data. It reads the encrypted data from the DB, and writes back encrypted data, only dealing with the unencrypted data in memory.
  So, in order to do this, the app is required to have the key stored in memory.</p>
  
  <p>The question is, is there any good best practices for this? Securing the key in memory.</p>
  
  <p>A few ideas:</p>
  
  <ol>
  <li>Keeping it in unswappable memory (for linux: setting <code>SHM_LOCK</code> with <code>shmctl(2)</code> ?)</li>
  <li>Splitting the key over multiple memory locations.</li>
  <li>Encrypting the key. With what, and how to keep the...key key.. secure?</li>
  <li>Loading the key from file each time its required (slow and if the evildoer can read our memory, he can probably read our files too)</li>
  </ol>
  
  <p>Some scenarios on why the key might leak: evildoer getting hold of mem dump/core dump; bad bounds checking in code leading to information leakage; </p>
  
  <p>The first one seems like a good and pretty simple thing to do, but how about the rest? Other ideas? Any standard specifications/best practices?</p>
  
  <p>Thanks for any input!</p>