Is there a way to produce two keys in string format, that are dependent on each other?
- Master key (to decrypt data)
- Slave key (dependent on the Master key, can only decrypt data)
Is there a way to produce two keys in string format, that are dependent on each other?
Nothing like a code story to explain the concept ;p
Here is an example where alice sends an encrypted message to bob using only bobs public key, bob then responds with an encrypted message using only alices public key.
In both cases their own private keys are used to decrypt the messages.
Yes, it's called Asymmetric Cryptography. Data is encrypted by using public key and then the private key is used to decrypt the data. This is used in many places e.g. in blockchains, payment portals etc.
You can find some helpful algorithms and theories here for understanding: https://www.tutorialspoint.com/cryptography/public_key_encryption.htm
In PHP, you can use -
openssl_encrypt()
&openssl_decrypt()
- to get the similar result or -base64_encode()
&base64_decode()
or you can mix both to get a more secured solution.One simple example can be:
To encrypt:
To decrypt:
Source: https://nazmulahsan.me/simple-two-way-function-encrypt-decrypt-string/