I am developing a web application in which each user has some part of his data that is stored encrypted. We are hosted on AWS and I want to use KMS as part of the solution. To not make the solution overly expensive (AWS charges per key) I was thinking of the following solution:

  1. I generate 1 RSA master key in AWS KMS
  2. For each user I generate an AES key (to be used later in GCM mode) in my application and store it encrypted using the public part of my master key (using PKCS#1 v2 padding).
  3. The user's data is encrypted using the AES key (GCM mode with random IV)
  4. When working with the data I only need to request KMS to decrypt the user AES key, all operations after that are done with the decrypted AES key

Is anybody aware of somebody using a solution like this or any security pitfalls? Yes - if the master private key leaks we are in trouble, but that is on AWS to protect.

  • 1
    $\begingroup$ I'm almost having to think about a large scale solution where I didn't do something like this. We had a colleague who wanted all keys to be generated and stored by an HSM all the time (including e.g. the session keys within TLS), but that quickly turns into madness. For file based encryption I would even advice against storing the data keys in an HSM; your processor has likely AES-NI support, and I would strongly advice you to use it. $\endgroup$
    – Maarten Bodewes
    Jul 11, 2022 at 14:12
  • 1
    $\begingroup$ You might want to use a specific key wrap function for the AES stuff. Also, keep in mind that there are limits to how much data can be encrypted with a single key using AES GCM (both in a single stream and over time). Nearly 64 GB for the former and for the latter it depends on your risk tolerance, but generally about the same. $\endgroup$ Jul 11, 2022 at 14:58
  • $\begingroup$ We are talking here about a few MB max. (<10) $\endgroup$
    – Adhocrat
    Jul 11, 2022 at 15:41
  • $\begingroup$ The data keys would be generated by the app (not KMS) and stored encrypted (with that 1 KMS key) in a DB. $\endgroup$
    – Adhocrat
    Jul 11, 2022 at 15:44


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.