Mega Code Archive

 
Categories / Php / Functions
 

Encrypting and Sending Secure Emails Using SMIME

<?php $message_headers = array('To: p@example.com',                          'From: b@example.com',                          'Subject: Summary'); if (openssl_pkcs7_encrypt('espionage_summary.txt', 'espionage_summary.pkcs7',  file_get_contents('phboss.crt'), $message_headers)) {   mail('phboss@thingy.exmaple.com',        'Espionage Summary',        file_get_contents('espionage_summary.pkcs7'),        $message_headers); } else {   die(openssl_error_string()); } ?> <?php $cert = file_get_contents('bob.crt'); $pkey = file_get_contents('bob.pem'); if (!openssl_pkcs7_decrypt('new_instructions.pkcs7',                            'new_instructions.txt',                            $cert, $pkey)) {   die(openssl_error_string()); } ? >