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:
And I'm pretty sure that this error is due to my message being greater than 4Kb. I have the following constraints.
- 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.
- I am searching for a lightweight approach so that I don't have many libraries and plugins added to the frontend code.
- 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:
- Hybrid encryption(outside AWS): Use a symmetric key to encrypt the message and use an asymmetric key to encrypt the symmetric key.
- 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