public and private keys
Sometimes I have to use public and private keys in my web applications and I had been blindly following AI prompts for doing this but a few days ago, I figured this out the whole rigamarole of *why* while revising the encryption section for the ... you guessed it ... pending AWS exam.
Using a combination of public and private keys is an asymmetric method of encryption. Using only a single key is the symmetric method and the same key is used for encrypting and decrypting.
Public keys can be shared and private keys are secret. The way that it works if your website is connected to a database for retrieving user account information - is that before database is stored, it's encrypted with the public key. Then in the server, that's where the private key lives (in config/env). When a user needs data, the server uses the private key to decrypt and then send it back to the browser.