title: What is the best way to keep database data encrypted with user passwords?
body: <p>Let's say an application has really specific data which belongs to a user, and nobody is supposed to see it except the owner. I use MySQL database with DataMapper ORM mapper. The application is written in Ruby on Sinatra. </p>
  
  <p>Application behavior:</p>
  
  <ol>
  <li>User signs up for an account. Creates username and password.</li>
  <li>Logs into his dashboard.</li>
  <li>Some fields in specific tables must be protected. </li>
  </ol>
  
  <p>Basically, I'm looking for auto-encryption for a model properties. Something like this:</p>
  
  <pre><code>class Transaction
    include DataMapper::Resource
  
    property :id, Serial
    property :value, String, :length =&gt; 1024, :encrypted =&gt; true
    ... etc ...
    belongs_to :user
  end
  </code></pre>
  
  <p>I assume that encryption/decryption on the fly will cause performance problems, but that's ok. At least if that works - I'm fine. </p>
  
  <p>Any ideas how to do this?</p>