Skip to content

Instantly share code, notes, and snippets.

@atmoner
Last active February 3, 2017 20:19
Show Gist options
  • Save atmoner/a24d58137882c3fa8012d43f4e4b39ce to your computer and use it in GitHub Desktop.
Save atmoner/a24d58137882c3fa8012d43f4e4b39ce to your computer and use it in GitHub Desktop.
(more info begin)
<?php
// the message you want to sign so that recipient can be sure it was you that
// sent it
$data = <<<EOD
You have my authorization to spend $10,000 on dinner expenses.
The CEO
EOD;
// save message to file
$fp = fopen("text.txt", "w");
fwrite($fp, $data);
fclose($fp);
// encrypt it
// Setup mail headers.
$headers = array("To" => "*************@gmail.com",
"From" => "contact.atmoner@gmail.com",
"Subject" => "A signed and encrypted message.");
$prepend = "file://";
openssl_pkcs7_sign(realpath(dirname(__FILE__)) . "/text.txt",
realpath(dirname(__FILE__)) . "/enc.txt",
$prepend . realpath(dirname(__FILE__)) ."/selfcert.pem",
array($prepend . realpath(dirname(__FILE__)) ."/enc_key.pem", "abcdef"), $headers);
$data = file_get_contents("enc.txt");
// separate header and body, to use with mail function
// unfortunate but required, else we have two sets of headers
// and the email client doesn't decode the attachment
$parts = explode("\n\n", $data, 2);
// send mail (headers in the Headers parameter will override those
// generated for the To & Subject parameters)
//if (isset($_GET['mail']))
mail("*****************@gmail.com", "test", $data, $parts[0]);
// sudo openssl req -x509 -days 365 -newkey rsa:1024 -keyout enc_key.pem -out selfcert.pem
// http://stackoverflow.com/questions/15237941/create-certificate-for-openssl-pkcs7-sign-in-php
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment