I have been tasked with developing a basic encryption add-on for a simple knowledge base/article application. The goal is to implement straightforward symmetric encryption without any complex features or a multitude of options.
While searching for JavaScript libraries or examples to help me achieve this, I have been surprised by the lack of available resources. Most search results seem to focus on criticizing browser encryption instead of providing practical solutions. Can you recommend a straightforward library or related resource for me to explore?
In the meantime, I have found that the Web Cryptography API offers a simple and accessible solution. After some experimentation, I have come up with the following code:
(code snippet here)
While this code works, it does feel somewhat convoluted. I am sure there must be a cleaner and more straightforward approach available. The nested layers of "thenables" do not appear very clean to me.
One final question I have is regarding the best method for storing the resulting cipher text and vector in MongoDB. Currently, I am outputting them as an array, which MongoDB interprets as an array of long integers. If I output them as a Typed Array, MongoDB sees them as an Object rather than an Array. Additionally, if I attempt to save them as "text," decryption no longer works properly.
How do others typically handle this? What is the best way to store these values in a database? If storing as "text," what is the optimal method for "armoring" a Typed Array to ensure secure storage and retrieval for decryption purposes?