0

I'm looking at strategies to encrypt my database. Using a public/private key pair seems to be the most adopted solution I've seen so far. Here for example How to encrypt user data in Firebase it is suggested that the user A public key gets stored in firebase and it's fetched by any user wanting to send him a message.

After user A logs in a random public private key pair is generated on his phone. eg.: use Ecc Curve25519 The private key from A is stored securely on his phone The public key from A is stored in firebase and is accessible to anybody that chats with A. If X sends a message to A he fetches the public key from A from firebase encrypts the message for A locally and stores the encrypted message on firebase in the inbox from A

As I understand it in case of an attacker getting access to the database he could decrypt the entire DB as he can access all the public keys. If this is the case then what's the point in encrypting it at all?

If instead the encryption/decryption key used is not stored in the Database the attacker would only get hold of encrypted data right? In this second scenario what would be the safest approach to serve users this key? Many thanks.

Vincenzo
  • 5,304
  • 5
  • 38
  • 96
  • 1
    Public keys are called public for a reason. They can only be used to **encrypt** and **verify** messages, hence they can be made public. That answer you quoted may be highly rated, but it is missing something critical: the lack of authentication on the public keys themselves. How does the user know it's really A's public key and not the attacker's? – President James K. Polk Nov 03 '20 at 16:54
  • @PresidentJamesK.Polk Thank you for answering . I see, public key can only be used to encrypt data but private key is needed to decrypt it so it's safe to have public key on db? what you mean by verify? can you please expand a bit on the lack of authentication on the public keys ? – Vincenzo Nov 03 '20 at 17:00
  • I re-read the answer again and the authentication part that I thought was missing is, in fact, there. The important authentication piece is "User A logs in", which can provide the necessary assurance. – President James K. Polk Nov 03 '20 at 17:07
  • @PresidentJamesK.Polk Can't `public key` also be used to decrypt data encrypted with `private key` ? – Vincenzo Nov 03 '20 at 17:34
  • No, a phone number can never be a safe encryption key, even if an attacker can't easily look it up she can still try them all to find the correct one. I would stick with the method in the answer. You might use a phone number as a second authentication factor though. – President James K. Polk Nov 03 '20 at 18:02
  • 1
    The private key is never used to encrypt data. The private key can be used to sign data, and particularly in RSA the signing operation is so similar to the encryption operation at the mathematical level that sometime people talk about "private key" encryption. But doing so just confuses the issue. – President James K. Polk Nov 03 '20 at 18:05
  • @PresidentJamesK.Polk Indeed phone verification is my second level of authentication, I guess that the classic passphrase answer will be safer to encrypt the private key and store it in database. Ok I get it..using the private for encryption is for sign data. Just to make sure.. A send a message to B encrypted with publicKey(B), B answer to A with a message encrypted first with privateKey(B) and then with publicKey(A). A can decrypt it with privateKey(A) and then if decrypting it with publicKey(B) succeeds it will prove that has been sent by B – Vincenzo Nov 03 '20 at 20:26

0 Answers0