I have a column in my database that I need to encrypt. The column can contain any arbitrary data.

What I am thinking is to generate a public and private key pair first. Store the public key in a configuration file and store the private key securely.

After that, for each row of data that I need to encrypt,

  1. Generate a cryptographically secure Key and IV
  2. Encrypt the data using the generated symmetric key
  3. Encrypt the symmetric key with the public key
  4. Store encrypted data, IV, encrypted symmetric key in the database

When I want decrypt it back,

  1. Decrypt symmetric key using private key
  2. Decrypt data using decrypted symmetric key and IV


  1. Is this asymmetric + symmetric key management needless?
  2. Is it good enough if I just encrypt and decrypt only by using asymmetric cryptography? If the length of data is small, is it ok ?
  3. Is storing the encrypted key in database a risk?
  • This is a too-specific question dressed as a legitimate one. Ironically, because your question can only be answered case-by-case, the answers would be too big for this site, so I voted to close as too broad. – Adi Aug 24 '13 at 6:37

In both steps, encryption and decryption, your application will be accessing the keys to access the data. More so, in the decryption case you'll have to find a way to securely access the supposedly securely-stored private key.

I see no point of using asymmetric cryptography. Use symmetric crypto (AES), store that key securely, and use that key to encrypt/decrypt your data.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.