2

I want to develop my own password manager, because all tools do not have the features I need. ;)

My question now is:

What would be a good and safe way to store passwords in a database when I want to decrypt those again when I need those in plain text?

dsprenkels
  • 1,464
  • 14
  • 21
Felix
  • 4,808
  • 9
  • 45
  • 130
  • It's not clear to me what you exactly mean. Do you want to store other user's passwords or do you want to build a password manager for yourself? – dsprenkels Aug 12 '17 at 09:37
  • I want to build a passwordmanager as a cloud service – Felix Aug 12 '17 at 09:59
  • 1
    You don't. See the [tag:password-encryption] tag for why not, and also [this answer](https://stackoverflow.com/questions/2283937/how-should-i-ethically-approach-user-password-storage-for-later-plaintext-retrie/2287672#2287672). There are **MAJOR** and company-busting reasons against this. Don't do it. – user207421 Aug 12 '17 at 11:23
  • Possible duplicate of [How should I ethically approach user password storage for later plaintext retrieval?](https://stackoverflow.com/questions/2283937/how-should-i-ethically-approach-user-password-storage-for-later-plaintext-retrie) – user207421 Aug 12 '17 at 11:23

3 Answers3

1

You mention the goal is to build a password manager as a cloud service. First I'd like to say that if you want to build this in production, you will want to have really good security consult. Also, before deploying this you will want to have it audited by a security company. Generally I'd recommend not going there at all.

Note: If you are doing this as a hobby project and only risk compromising your own security, go for it. I have also once built such a system for myself (although I never used it :P).

The most secure way of storing the passwords is by only storing the encrypted form on the server. Most importantly, store the key on the user's device and do all the encryption/decryption there. In theory, as long as the key stays on the device, the passwords are secure, even if the server is hacked.

In practice this is a Hard Problem. You have to think of using a 2nd factor for decryption (keyfiles, passwords, maybe NFC tokens), backups, access control, key revocation, re-encryption, protection against data exfiltration (keyloggers, screenshots, clipboard, side-channel attacks), et cetera. All these factors make it nigh-on impossible to make these kinds of schemes both usable and secure.

dsprenkels
  • 1,464
  • 14
  • 21
0

If you want to store password safely, you should consider "hashing" the passwords, maybe with a salt. Consider reading this Wikipedia article, which covers hash and salt.

But if you need to recover the original text, you will need a key to encrypt/decrypt your password. This means you have to save the key somewhere in your code, or at least your system is able to recover the key somehow. If an attacker has access to the location of the key, or the code of your application, along with the encrypted passwords, you could end up with stolen passwords!

Anyway, you need an answer to your question: you can look up for a simmetric or asimmetric cryptography, it depends on your needs. For example, you can loop up for AES, which needs a key for encryption/decryption (along with the original/encrypted text, obviously). You didn't specified a programming language, but you can find plenty of libraries which do this!

FonzTech
  • 369
  • 1
  • 4
  • 13
  • I want to develop in scala sorry for that. do you probably have a hint for me? – Felix Jul 31 '17 at 16:52
  • When saving a password verifier just using a hash function is not sufficient and just adding a salt does little to improve the security. – zaph Jul 31 '17 at 18:17
  • Zaph, just give your full answer for this question, instead of downvoting all the answers... – FonzTech Aug 01 '17 at 02:25
  • 1
    the problems with the answer: 1. The OP specifically states it is a requirement to recover the passwords so a password verifier is not a solution. 2. In the case of password verifiers in situations where they are required they need to be secure to protect the users. 3. Asymmetric is not required for the OP's use, symmetric encryption is the appropriate. 4. Suggestion: re-work the answer to remove the non-compliant portions and it would be worthy of an up-vote. – zaph Aug 01 '17 at 02:51
  • OT: I have things going on. Peace – FonzTech Aug 02 '17 at 21:32
0

It is usually a good idea to use existing, trusted implementations. Cryptography is a broad and complicated field, and it requires a lot of knowledge to design and implement something secure. In general that means: Stick to existing algorithms that are a) commonly used and b) not yet broken. Also, don't implement algorithms yourself, but use existing, reviewed implementations wherever possible. It is just too easy to screw up, even for experts (cf. Debian weak key debacle).

Since you want to be able to obtain plain text again, Hash functions are not an option. That leaves you with symmetric and asymmetric encryption. Asymmetric encryption uses different keys for encryption and decryption, which is not really something you want for a password manager. So symmetric encryption is probably the way to go. But that still leaves you with tons of different algorithms (AES, Blowfish and Serpent just to name a few).

After choosing an algorithm, you still would have to implement encryption and decryption of your database, ideally in a fast and secure manner. Instead of implementing this yourself, it is probably a good idea to stick to a proven solution. The enpass password manager uses SQLCipher to encrypt an sqlite database. SQLCipher has a Java API, so it shouldn't be too complicated to use it in Scala.

Daniel Klischies
  • 755
  • 5
  • 13
  • What is a possible justification for recommending Blowfish or Serpent in place of AES? Note that the author of Blowfish has stated he does not use it and uses AES. Otherwise a nice answer. – zaph Jul 31 '17 at 20:48
  • I'm not recommending any of those in place of AES, but neither am I recommending AES in place of Serpent (maybe I'd use recommend AES compared to blowfish, but not compared to twofish). As long as neither has been broken, I'd consider them equally secure. If you want to be really sure you could still nest all these algorithms into each other: Encrypt your password using Serpent, then encrypt the result using Twofish and then encrypt the result of that using AES. Thats what Veracrypt is doing, and in order to break it you need to break all three encryption layers. – Daniel Klischies Aug 01 '17 at 11:52