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.