note 36653 modified in function.openssl-pkcs7-sign by didou

From: Date: Mon, 20 Oct 2003 11:35:39 +0000
Subject: note 36653 modified in function.openssl-pkcs7-sign by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58931@lists.php.net to get a copy of this message
This command doesn't work correctly on WIN32 with IIS. Mails aren’t interpreted correctly by IIS SMTP Server (and by Outlook too). The reason is that UNIX and WINDOWS interpret the “enter to the next line” ascii code in a different way. Below I present an improved code: <?php $data = <<<EOD Testing 123 This is a test Test EOD; //save the message to a file $fp = fopen("msg.txt","w"); fwrite($fp,$data); fclose($fp); //sign the message using the sender's keys openssl_pkcs7_sign("msg.txt", "signed.eml", "file://c:/max/cert.pem", array("file://c:/max/priv.pem","your_password"), array("To" => "recipient <recipients@mail.com>", "From" => "sender <sender@mail.com>", "Subject" => "Order Notification - Test"),PKCS7_DETACHED,"c:\max\extra_cert.pem"); $file_arry = file("signed.eml"); $file = join ("", $file_arry); $message = preg_replace("/\r\n|\r|\n/", "\r\n", $file); $fp = fopen("c:\Inetpub\mailroot\Pickup\signed.eml", "wb"); flock($fp, 2); fputs($fp, $message); flock($fp, 3); fclose($fp); ?> Besides, if you want to use the keys created with Windows, you should export them (from IE) to the form of PKCS#12 file (*.pfx). Install OpenSSLWin32 from http://www.shininglightpro.com/search.php?searchname=Win32+OpenSSL execute: openssl.exe enter the commands: pkcs12 -in <pfx-file> -nokeys -out <pem-certs-file> pkcs12 -in <pfx-file> -nocerts -nodes -out <pem-key-file> Next export from IE Root CA certificate as Base-64 *.cer and rename the file to *.pem And that's all! --was-- This command doesn't work correctly on WIN32 with IIS. Mails aren’t interpreted correctly by IIS SMTP Server (and by Outlook too). The reason is that UNIX and WINDOWS interpret the “enter to the next line” ascii code in a different way. Below I present an improved code: <?php $data = <<<EOD Testing 123 This is a test Test EOD; //save the message to a file $fp = fopen("msg.txt","w"); fwrite($fp,$data); fclose($fp); //sign the message using the sender's keys openssl_pkcs7_sign("msg.txt", "signed.eml", "file://c:/max/cert.pem", array("file://c:/max/priv.pem","dupa"), array("To" => "recipient <maciej_niemir@ilim.poznan.pl>", "From" => "sender <Maciej_Niemir@ilim.poznan.pl>", "Subject" => "Order Notification - Test"),PKCS7_DETACHED,"c:\max\ilim.pem"); $file_arry = file("signed.eml"); $file = join ("", $file_arry); $message = preg_replace("/\r\n|\r|\n/", "\r\n", $file); $fp = fopen("c:\Inetpub\mailroot\Pickup\signed.eml", "wb"); flock($fp, 2); fputs($fp, $message); flock($fp, 3); fclose($fp); ?> Besides, if you want to use the keys created with Windows, you should export them (from IE) to the form of PKCS#12 file (*.pfx). Install OpenSSLWin32 from http://www.shininglightpro.com/search.php?searchname=Win32+OpenSSL execute: openssl.exe enter the commands: pkcs12 -in <pfx-file> -nokeys -out <pem-certs-file> pkcs12 -in <pfx-file> -nocerts -nodes -out <pem-key-file> Next export from IE Root CA certificate as Base-64 *.cer and rename the file to *.pem And that's all! http://www.php.net/manual/en/function.openssl-pkcs7-sign.php

« previous php.notes (#58931) next »