I am working on a password sharing web site. I would like users to be able to enter their credentials and share them with other users. I am thinking about using KMS service to store master key (just one) and have a database to store key - credentials pairs. User's credentials will be encrypted with the key from the database and the key stored in the database (different for each credentials) will be encrypted using KMS master key. AES encryption algorithms will be used for both: encrypting user's credentials and encrypting the key used to encrypt the credentials. Would it be secure enough to store encrypted key along with credentials or is there a better approach?

  • 2
    Sharing passwords is something people should never ever do. Please don't create a site telling them that it's ok. ... And, if you need to ask such questions, please don't try to make something like that too. – user155462 Feb 6 '18 at 7:48
  • I can't quite follow your explaination and get really confused about the keys in use. Could you assign letters to them, i.e. "Key B is created by [...], while Key A is used to encrypt Key B" and rephrase your question for it to be understood more easily? – GxTruth Feb 6 '18 at 8:38
  • @user155462 Sharing credentials is the main purpose of the project I am working on. – Vitalii Kalinin Feb 10 '18 at 17:03
  • @GxTruth Key M is the master key stored on a dedicated server (probably KMS), database server generates new Key X for each username/password and then Key M is used to encrypt Key X. Encrypted Key X is stored along with the username/password. – Vitalii Kalinin Feb 10 '18 at 17:09
  • @VitaliiKalinin So what? That makes it worse. ... Namely, that this is the focus of the project is already worse than just a side feature, but that there isn't even a specific use case, other than to share (for any use case), is the worst. – user155462 Feb 12 '18 at 12:10

The real question to ask is "what is your threat model?" What sort of attack are you trying to prevent? Are you creating a digital lock on a diary to keep it safe from your sister's prying eyes, or are you Edward Snowden, on the run from several three letter agencies with billions of dollars of funding? AES-256 is currently labeled as sufficient to use in the US government for the transmission of TOP SECRET/SCI information. That's pretty much the highest classification level they could clear it for, so the US government is pretty darn confident that nobody can break AES-256 on the timescales required to protect our nation's greatest secrets. (Well, almost. What it really says is that they are confident that nobody outside of the US government can break AES-256. What you believe that that says about whether the US government, themselves, can break it depends on your threat model... and whether you engage in discussions of whether heavy-duty tin foil makes better hats or not)


AES key encryption is secure enough for keeping the data safe. In my opinion if the master key M is compromised, it can lead to decrypting all the key X. If you use a public key encryption to encrypt key X, only a partial of the data would be compromised. Say for example, there are two users U1 and U2, and there public keys be PubU1 and PubU2, private key be PriU1 and PriU2.

When U1 want to share his credentials with U2, the application uses PubU2 to encrypt the key X, so that when U2 want to access the data he will first decrypt using PriU2 and then uses key X to decrypt the data.

| improve this answer | |
  • The key stored along with credentials (Key X) is encrypted with the master key (Key M), which is stored on a dedicated server (probably KMS) – Vitalii Kalinin Feb 10 '18 at 17:11
  • Modified my answer based on your comment – Daniel Netto Feb 11 '18 at 18:23
  • Thanks for feedback. Yes I agree if Key M is compromised and attacker has access to server with credentials and Keys X he can decrypt it. Which is why I think about using KMS (which suppose to keep your key safe). The problem with asymmetric approach in my case is that one password can be shared among 3 or more people. So if U1 want to share credentials with U2 and U3, the app would need to either use same Key for U2 & U3, or generate two encrypted instances. – Vitalii Kalinin Feb 22 '18 at 1:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.