PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

openssl_pkey_export_to_file> <openssl_pkcs7_sign
Last updated: Fri, 10 Oct 2008

view this page in

openssl_pkcs7_verify

(PHP 4 >= 4.0.6, PHP 5)

openssl_pkcs7_verifyS/MIME でサインされたメッセージの署名を検証する

説明

mixed openssl_pkcs7_verify ( string $filename , int $flags [, string $outfilename [, array $cainfo [, string $extracerts [, string $content ]]]] )

openssl_pkcs7_verify() は、 指定したファイルの S/MIME メッセージを読み込み、デジタル署名を評価します。

パラメータ

filename

メッセージへのパス。

flags

flags により署名の検証方法を指定することが可能です。 詳細については、PKCS7 定数 を参照ください。

outfilename

outfilename を指定する場合、 メッセージに署名した人の証明書が PEM 形式で保存されたファイルの名前をこの変数に指定する必要があります。

cainfo

cainfo が指定された場合、 検証処理で使用するために認証済みの CA 証明書に関する情報を保持する必要があります。 このパラメータに関するより詳細な情報については、 証明書の検証 を参照ください。

extracerts

extracerts が指定された場合、 これは未認証の CA として一連の証明書を使用するためのファイルの名前となります。

content

ファイル名とともに content を指定すると、検証したデータがここに格納されます。 格納する際に、署名情報は除去されます。

返り値

署名が検証された場合は TRUE、正しくない場合 (メッセージが改暫されたか署名に用いられた証明書が無効) は FALSE、 エラーの場合に -1 を返します。

変更履歴

バージョン 説明
5.1.0 content パラメータが追加されました。



add a note add a note User Contributed Notes
openssl_pkcs7_verify
hema
29-Sep-2006 11:39
As someone already mentioned in the previous comment it didn't work for me until I passed in that hidden sixth argument and also explicitly add the mime header into the $in_filename contents. (I am using PHP5)

 $data = file_get_contents($in_filename);

 file_put_contents($in_filename, "MIME-Version: 1.0\nContent-Disposition: attachment; filename=\"smime.p7m\"\nContent-Type: app
lication/x-pkcs7-mime; name=\"smime.p7m\"\nContent-Transfer-Encoding: base64\n\n$data");

 openssl_pkcs7_verify("$in_filename",
                              $flag,
                              "$out_filename.cert",
                              array($path_to_cert),
                              $path_to_cert,
                              $out_filename));
14-Feb-2006 01:59
There is a hidden sixth argument: string pointing to a file where the contents of the signed message should be saved.

It is very important for verifying signed and encrypted messages from MS Outlook which uses opaque signing. After decrypting of message you will get another MIME envelope like this:

MIME-Version: 1.0
Content-Disposition: attachment; filename="smime.p7m"
Content-Type: application/x-pkcs7-mime; smime-type=signed-data; name="smime.p7m"
Content-Transfer-Encoding: base64

MIIM/QYJ...

Even if you use base64_decode() you will not get decrypted message but PKCS #7 object.

BTW: How to create opaque signed message like from MS Outlook? Switch off PKCS7_DETACHED flag (the last 0 does it):
openssl_pkcs7_sign(
    "full_path_to_message_file",
    "full_path_where_to_store_signed_message_file",
    "file://full_path_to_my_public_certificate.pem",
    array("file://full_path_to_my_private_key.pem", "password"),
    array(),
    0
  );

openssl_pkey_export_to_file> <openssl_pkcs7_sign
Last updated: Fri, 10 Oct 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites