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,
- Generate a cryptographically secure Key and IV
- Encrypt the data using the generated symmetric key
- Encrypt the symmetric key with the public key
- Store encrypted data, IV, encrypted symmetric key in the database
When I want decrypt it back,
- Decrypt symmetric key using private key
- Decrypt data using decrypted symmetric key and IV
- Is this asymmetric + symmetric key management needless?
- 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 ?
- Is storing the encrypted key in database a risk?