This may be more suitable for StackOverflow in terms of a recommendation for a library or implementation, but security-related questions are often overlooked or misinterpreted. I'd like to first understand whether the proposed mechanism is an apt solution, as well as a means to implement said solution.
I will simplify my use-case in order to avoid going into sensitive details.
I'd like to develop a web application that provides a cloud-based service. The app logic makes use of a secret key. The secret should only be known to the client at all times, and sensitive data that is encrypted using this key should never be sent out from the client in unencrypted form. I will need to store the client's sensitive data in encrypted form within the cloud-based database.
To clarify, all traffic will be over HTTPS, but I don't want the client's sensitive data to be sent to the cloud or stored in the cloud DB in unencrypted form at any point in time.
My initial thought was to generate a public/private key pair using some client-side logic. The client will then save the private key on the client side (this may be LocalStorage for the sake of simplification) for later encryption of sensitive data.
The client will then send the public key to the cloud-based server, which will store it in the cloud-based DB, for storing any data meant for the client that should not be stored unencrypted.
Now whenever the client wants to store sensitive information in the cloud DB, the private key saved on the client side will be used to encrypt said data, and the encrypted data will be sent to the DB and stored.
When the client wants to retrieve stored information, it will be fetched, and then decrypted by the client-side app using the private key stored "offline"/in the browser/in a file. I realize what I've described might be referred to as a "zero-knowledge" system, but I'm not labelling it as such so as not to cause any confusion about the intended result.
I'd like to understand what flaws exist in the proposed solution, and I'd also like to know of any mature implementations for something along these lines.
I would prefer a JavaScript library that can both generate and also encrypt/decrypt data, and I am aware of questions such as this one and this one as well as the linked articles, but since the question and the articles are outdated, and since browsers an JavaScript have progressed rapidly over the last years, I see fit to ask about JS once again.
I also read this question which is more generalized and doesn't mention specific implementations or libraries -- also, I'm positive I want client-side key generation.
Another option may be a Bash or other CLI tool implementation.
The project is a work in progress, nothing is final. Obviously I'm not looking to roll my own crypto, so I'd like to find a vetted option that serves the purpose. Completely open to ideas/suggestions/rejections, I'm looking to learn and adapt myself.