首页 >函数列表 >openssl_pkcs7_sign

openssl_pkcs7_sign

openssl_pkcs7_sign

(PHP 4 >= 4.0.6, PHP 5)

openssl_pkcs7_signSign an S/MIME message

说明

bool openssl_pkcs7_sign ( string $infilename , string $outfilename , mixed $signcert , mixed $privkey , array $headers [, int $flags = PKCS7_DETACHED [, string $extracerts ]] )

openssl_pkcs7_sign() takes the contents of the file named infilename and signs them using the certificate and its matching private key specified by signcert and privkey parameters.

参数

infilename

outfilename

signcert

privkey

headers

headers is an array of headers that will be prepended to the data after it has been signed (see openssl_pkcs7_encrypt() for more information about the format of this parameter).

flags

flags can be used to alter the output - see PKCS7 constants.

extracerts

extracerts specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE.

范例

Example #1 openssl_pkcs7_sign() example

<?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("msg.txt""w");
fwrite($fp$data);
fclose($fp);
// encrypt it
if (openssl_pkcs7_sign("msg.txt""signed.txt""mycert.pem",
    array(
"file://mycert.pem""mypassphrase"),
    array(
"To" => "joes@example.com"// keyed syntax
          
"From: HQ <ceo@example.com>"// indexed syntax
          
"Subject" => "Eyes only")
    )) {
    
// message signed - send it!
    
exec(ini_get("sendmail_path") . " < signed.txt");
}
?>


  • openssl_cipher_iv_length
  • openssl_csr_export
  • openssl_csr_export_to_file
  • openssl_csr_get_public_key
  • openssl_csr_get_subject
  • openssl_csr_new
  • openssl_csr_sign
  • openssl_decrypt
  • openssl_dh_compute_key
  • openssl_digest
  • openssl_encrypt
  • openssl_error_string
  • openssl_free_key
  • openssl_get_cipher_methods
  • openssl_get_md_methods
  • openssl_get_privatekey
  • openssl_get_publickey
  • openssl_open
  • openssl_pkcs12_export
  • openssl_pkcs12_export_to_file
  • openssl_pkcs12_read
  • openssl_pkcs7_decrypt
  • openssl_pkcs7_encrypt
  • openssl_pkcs7_sign
  • openssl_pkcs7_verify
  • openssl_pkey_export
  • openssl_pkey_export_to_file
  • openssl_pkey_free
  • openssl_pkey_get_details
  • openssl_pkey_get_private
  • openssl_pkey_get_public
  • openssl_pkey_new
  • openssl_private_decrypt
  • openssl_private_encrypt
  • openssl_public_decrypt
  • openssl_public_encrypt
  • openssl_random_pseudo_bytes
  • openssl_seal
  • openssl_sign
  • openssl_verify
  • openssl_x509_checkpurpose
  • openssl_x509_check_private_key
  • openssl_x509_export
  • openssl_x509_export_to_file
  • openssl_x509_free
  • openssl_x509_parse
  • openssl_x509_read
  • PHP MySQL HTML CSS JavaScript MSSQL AJAX .NET JSP Linux Mac ASP 服务器 SQL jQuery C# C++ java Android IOS oracle MongoDB SQLite wamp 交通频道