I would create S / MIME public / private key pairs using OpenSSL and then using the OpenSSL command to encrypt and decrypt. I believe this is superior to using PGP because openssl is included in most Linux operating systems, and PGP is not. OpenSSL is also standards-based and generally easier to work with when you have down commands.
I recommended against a "pure" PHP solution (with pure-PHP I mean doing cryptography in PHP, instead of using PHP to call an existing library or a separate executable file). You do not want to do massive cryptography in PHP. Too slow. And you want to use OpenSSL because it is well versed in high performance and security.
Here is the magic.
To make an X.509 key:
$subj="/C=US/ST=California/L=Remote/O=Country Govt./OU=My Dept/CN=Mr. Agent/emailAddress=agent@investiations.com" openssl req -x509 -newkey rsa:1024 -keyout mycert.key -out mycert.pem -nodes -subj $subj
This puts the private key in mycert.key and the public key in mycert.pem. The private key is not password protected.
Now, to sign the message with S / MIME:
openssl smime -sign -signer mycert.pem -inkey mycert.key <input >output
To encrypt a message using S / MIME:
openssl smime -encrypt -recip yourcert.pem <input >output
To decrypt a message using S / MIME:
openssl smime -decrypt -inkey mycert.key -certfile mycert.pem <input >output
I also have some demos of using OpenSSL from C language bindings, but not from PHP.
vy32 Jan 14 2018-11-11T00: 00Z
source share