I have a public database where users need to store configuration files. The file can contain passwords. Everyone can read config files but only the server can read passwords in them.
In the browser, when a user wants to add a password to the the config file:
- User hash the password using bcrypt
- User encrypts the hashed string with public key A
- User adds the encrypted string to the config file and saves it to the database
A third party server will then connect to the database, this server knows the private key for A. This server verifies if some plaintext password match with the encrypted hash. Other users see the config file, but they can't see what passwords are in it.
Some precision :
- I don't care if another user edits the encrypted password, and I don't care who edits the password, so I don't think I need to sign anything.
- It's really a public database, like a mysql instance without any security.
- I do the hashing on the client in case the private key gets stolen. It will take a long time to reverse the hash for all passwords.
It seems secure to me. Is it? Is there a simpler way?