Code­Reaper

Asymmetric encryption in PHP

2014

One of the use cases of asymmetric encryption is to allow others to send you encrypted data that only you can read.
No one says the receiver and sender are both running PHP, in fact there will be multiple language examples available.

This type of encryption is also refered to as public key cryptography, because it requires you to use a private key and a public key.

The encryption and decryption methods you will want to use is openssl_​seal and openssl_​open, but they do require a little extra of you as a developer.
You need to manage not just the encrypted bytes, but also some extra bytes that match the public key used to encrypt the data. This is because the sealing method allows you to encrypt the same data for multiple recipients.

There and back again

Below is an example of how to generate sealed data and an envelope and use them to recreate the original data: