This is not for a production application, but just my exploration to help me understand cryptography.

At the simplest level, I want to design a key-value store for user secrets.

This is exposed over an HTTPS API with usual create-read-update-delete operations supported: send a post request with a body of a sercret, the server encrypts and stores that secret, then returns back an id for that secret; send a get to the id and get back the decrypted secret; etc.

This service receives requests from other microserivces in the network on behalf of the user.

How should the service protect a user's secrets, and protect against unauthorized access to this API?

I know that in some way the service needs to authenticate and authorize the request from both the upstream service and the user.

What's a good way to pair these? One idea I have is something like...

  1. Generate a key
  2. Encrypt the secret using the key
  3. Store the encrypted secret
  4. Encrypt the key using...? something from the server + user - a shared secret maybe?
  5. Store the encrypted key
  6. Return to the user an id (token)

And to retrieve the secret:

  1. user/other service requests id from server
  2. server + user shared secret decrypts key
  3. key decrypts secret
  4. send secret to user

1 Answer 1


Your application is the simplest form of an encrypted pastebin for example, for something like this you can take a look here. Also, there isn't a golden rule on how to design such an application. It really depends on the specifications you set. For example, the ideal from a security perspective is to encrypt the secrets client side and the server then just becomes a simple database. It can indeed be replaced by a db service and not an http api but you can build an http api on top of the db service as well. On the other hand, you may want to make your api accessible to low/end low powered devices, then you have to choose an appropriate cipher for this if you want to support client side encryption. If for some reason you want to restrict yourself to server side encryption there are a lot of methods that you can use but things get a bit more complicated here (let me know if you want to update my answer). Also you may be interested to add password authentication in order for example only registered or invited users to be able to store secrets, for this you can use an SRP protocol. Again, these are only a few ideas and resources to get you started.

  • $\begingroup$ Thank you, that's very helpful! The encrypted pastebin is a nice resource I wasn't aware of. Could you elaborate on what it could look like to restrict to server side encryption? Say that the server uses aes-256-gcm for encryption - would the user send the key, or would the server encrypt a user passphrase that is then used as the key for the aes-gcm encryption, maybe? $\endgroup$
    – user104510
    Oct 22, 2022 at 8:55
  • $\begingroup$ @MaheshSundaram For server side encryption, it depends on what security levels you want to achieve. For example, in the simplest case to achieve security you have to consider the server as a trusted third party. Both scenarios you mention don't make a difference from the security wise perspective. $\endgroup$
    – tur1ng
    Oct 22, 2022 at 11:40

Your Answer

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