Which is an appropriate way to encrypt message of size greater than 4KB?

Viewed 361

I have been working to encrypt messages of size greater than 4Kb using AWS KMS. As I went through the AWS KMS documentation, the maximum size of a message that can be encrypted using AWS KMS is only 4Kb. I tried using both symmetric and asymmetric keys types to encrypt the message, but couldn't get the expected results. This is the error screenshot: enter image description here

And I'm pretty sure that this error is due to my message being greater than 4Kb. I have the following constraints.

  1. The encryption has to be on the frontend. This is creating a problem to use a symmetric approach because the key that I use may be easily seen to end users even the frontend code is minified.
  2. I am searching for a lightweight approach so that I don't have many libraries and plugins added to the frontend code.
  3. As I went through several articles what I found is if I use the asymmetric approach, there is always a limitation of message size that can be encrypted.

I was focusing on AWS KMS because I am using aws-sdk already in my front-end code and any solution with the same SDK won't increase my code size.

So, the possible alternatives I have found as per my study(not 100% sure) are:

  1. Hybrid encryption(outside AWS): Use a symmetric key to encrypt the message and use an asymmetric key to encrypt the symmetric key.
  2. Envelope encryption(with AWS)(Not sure how we can implement this)

Therefore, I am searching for references around AWS illustrating Envelope Encryption (with example if possible) or any other solutions satisfying the above-mentioned constraints. If around AWS is not possible, any lightweight approaches(with practical implementation) that can be implemented on the frontend would also be highly appreciated.

Programming Language: Javascript

0 Answers
Related