note 36653 added to function.openssl-pkcs7-sign
| From: | Maciej_Niemir at rn2 dot php dot net | Date: | Fri, 17 Oct 2003 11:46:41 +0000 |
| Subject: | note 36653 added to function.openssl-pkcs7-sign | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-58754@lists.php.net to get a copy of this message | ||
This command doesn't work correctly on WIN32 with IIS. Mails arent 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!
----
Manual Page -- http://www.php.net/manual/en/function.openssl-pkcs7-sign.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36653
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36653&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36653&report=yes
Search -- http://master.php.net/manage/user-notes.php