<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >OpenSSL Functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Documentaþia funcþiilor" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="ociwritetemporarylob" HREF="function.ociwritetemporarylob.html"><LINK REL="NEXT" TITLE="openssl_csr_export_to_file" HREF="function.openssl-csr-export-to-file.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.ociwritetemporarylob.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.openssl-csr-export-to-file.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.openssl" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >LXXVIII. OpenSSL Functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN84383" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.intro" >Introducere</A ></H1 ><P > This module uses the functions of <A HREF="http://www.openssl.org/" TARGET="_top" >OpenSSL</A > for generation and verification of signatures and for sealing (encrypting) and opening (decrypting) data. OpenSSL offers many features that this module currently doesn't support. Some of these may be added in the future. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.requirements" >Necesitãþi</A ></H1 ><P > In order to use the OpenSSL functions you need to install the <A HREF="http://www.openssl.org/" TARGET="_top" >OpenSSL</A > package. PHP between versions 4.0.5 and 4.3.1 will work with OpenSSL >= 0.9.5. Other versions (PHP <=4.0.4pl1 and >= 4.3.2) require OpenSSL >= 0.9.6. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Avertisment</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > You are strongly encouraged to use the most recent OpenSSL version, otherwise your web server could be vulnerable to attack. </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.installation" >Instalare</A ></H1 ><P > To use PHP's OpenSSL support you must also compile PHP <VAR CLASS="option" >--with-openssl[=DIR]</VAR >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note to Win32 Users: </B > In order to enable this module on a Windows environment, you must copy <TT CLASS="filename" >libeay32.dll</TT > from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: <TT CLASS="filename" >C:\WINNT\SYSTEM32</TT > or <TT CLASS="filename" >C:\WINDOWS\SYSTEM32</TT >) </P ><P > Additionally, if you are planning to use the key generation and certificate signing functions, you will need to install a valid <TT CLASS="filename" >openssl.cnf </TT > on your system. As of PHP 4.3.0, we include a sample configuration file in the <TT CLASS="filename" >openssl</TT > folder of our win32 binary distribution. If you are using PHP 4.2.0 or later and are missing the file, you can obtain it from <A HREF="http://www.openssl.org/" TARGET="_top" >the OpenSSL home page</A > or by downloading the PHP 4.3.0 release and using the configuration file from there. </P ><P ><B >Note to Win32 Users: </B > PHP will search for the <TT CLASS="filename" >openssl.cnf</TT > using the following logic: <P ></P ><UL ><LI ><P >the <VAR CLASS="literal" >OPENSSL_CONF</VAR > environmental variable, if set, will be used as the path (including filename) of the configuration file. </P ></LI ><LI ><P >the <VAR CLASS="literal" >SSLEAY_CONF</VAR > environmental variable, if set, will be used as the path (including filename) of the configuration file. </P ></LI ><LI ><P >The file <TT CLASS="filename" >openssl.cnf</TT > will be assumed to be found in the default certificate area, as configured at the time that the openssl DLL was compiled. This is usually means that the default filename is <TT CLASS="filename" >c:\usr\local\ssl\openssl.cnf</TT >. </P ></LI ></UL > </P ><P > In your installation, you need to decide whether to install the configuration file at <TT CLASS="filename" >c:\usr\local\ssl\openssl.cnf</TT > or whether to install it someplace else and use environmental variables (possibly on a per-virtual-host basis) to locate the configuration file. Note that it is possible to override the default path from the script using the <VAR CLASS="parameter" >configargs</VAR > of the functions that require a configuration file. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.configuration" >Configurare la rulare</A ></H1 ><P >Aceastã extensie nu defineºte directive de configurare.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.resources" >Tipuri de resurse</A ></H1 ><P > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.certparams" >Key/Certificate parameters</A ></H1 ><P > Quite a few of the openssl functions require a key or a certificate parameter. PHP 4.0.5 and earlier have to use a key or certificate <A HREF="language.types.resource.html" ><B CLASS="type" >resource</B ></A > returned by one of the openssl_get_xxx functions. Later versions may use one of the following methods: <P ></P ><UL ><LI ><P > Certificates <P ></P ><OL TYPE="1" ><LI ><P > An X.509 resource returned from <A HREF="function.openssl-x509-read.html" ><B CLASS="function" >openssl_x509_read()</B ></A > </P ></LI ><LI ><P >A string having the format <TT CLASS="filename" >file://path/to/cert.pem</TT >; the named file must contain a PEM encoded certificate </P ></LI ><LI ><P > A string containing the content of a certificate, PEM encoded </P ></LI ></OL > </P ></LI ><LI ><P > Public/Private Keys <P ></P ><OL TYPE="1" ><LI ><P >A key resource returned from <A HREF="function.openssl-get-publickey.html" ><B CLASS="function" >openssl_get_publickey()</B ></A > or <A HREF="function.openssl-get-privatekey.html" ><B CLASS="function" >openssl_get_privatekey()</B ></A > </P ></LI ><LI ><P >For public keys only: an X.509 resource</P ></LI ><LI ><P >A string having the format <TT CLASS="filename" >file://path/to/file.pem</TT > - the named file must contain a PEM encoded certificate/private key (it may contain both) </P ></LI ><LI ><P > A string containing the content of a certificate/key, PEM encoded </P ></LI ><LI ><P > For private keys, you may also use the syntax <SPAN CLASS="emphasis" ><I CLASS="emphasis" >array($key, $passphrase)</I ></SPAN > where $key represents a key specified using the file:// or textual content notation above, and $passphrase represents a string containing the passphrase for that private key </P ></LI ></OL > </P ></LI ></UL > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.cert.verification" >Certificate Verification</A ></H1 ><P > When calling a function that will verify a signature/certificate, the <SPAN CLASS="emphasis" ><I CLASS="emphasis" >cainfo</I ></SPAN > parameter is an array containing file and directory names that specify the locations of trusted CA files. If a directory is specified, then it must be a correctly formed hashed directory as the <B CLASS="command" >openssl</B > command would use. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.constants" >Constante predefinite</A ></H1 ><P > Aceste constante sunt definite de aceastã extensie ºi vor fi disponibile doar cînd extensia a fost fie compilatã odatã la instalarea PHP fie dacã extensia este încãrcatã dinamic la rulare.</P ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="openssl.purpose-check" >Purpose checking flags</A ></H2 ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_SSL_CLIENT</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_SSL_SERVER</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_NS_SSL_SERVER</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_SMIME_SIGN</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_SMIME_ENCRYPT</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_CRL_SIGN</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_ANY</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="openssl.padding" >Padding flags</A ></H2 ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >OPENSSL_PKCS1_PADDING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_SSLV23_PADDING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_NO_PADDING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_PKCS1_OAEP_PADDING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="openssl.key-types" >Key types</A ></H2 ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >OPENSSL_KEYTYPE_RSA</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_KEYTYPE_DSA</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_KEYTYPE_DH</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="openssl.pkcs7.flags" >PKCS7 Flags/Constants</A ></H2 ><P > The S/MIME functions make use of flags which are specified using a bitfield which can include one or more of the following values: <DIV CLASS="table" ><A NAME="AEN84567" ></A ><P ><B >Tabel 1. PKCS7 CONSTANTS</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >Constant</TH ><TH >Description</TH ></TR ></THEAD ><TBODY ><TR ><TD >PKCS7_TEXT</TD ><TD >Adds text/plain content type headers to encrypted/signed message. If decrypting or verifying, it strips those headers from the output - if the decrypted or verified message is not of MIME type text/plain then an error will occur.</TD ></TR ><TR ><TD >PKCS7_BINARY</TD ><TD >Normally the input message is converted to "canonical" format which is effectively using CR and LF as end of line: as required by the S/MIME specification. When this options is present, no translation occurs. This is useful when handling binary data which may not be in MIME format.</TD ></TR ><TR ><TD >PKCS7_NOINTERN</TD ><TD >When verifying a message, certificates (if any) included in the message are normally searched for the signing certificate. With this option only the certificates specified in the <VAR CLASS="parameter" >extracerts</VAR > parameter of <A HREF="function.openssl-pkcs7-verify.html" ><B CLASS="function" >openssl_pkcs7_verify()</B ></A > are used. The supplied certificates can still be used as untrusted CAs however. </TD ></TR ><TR ><TD >PKCS7_NOVERIFY</TD ><TD >Do not verify the signers certificate of a signed message.</TD ></TR ><TR ><TD >PKCS7_NOCHAIN</TD ><TD >Do not chain verification of signers certificates: that is don't use the certificates in the signed message as untrusted CAs. </TD ></TR ><TR ><TD >PKCS7_NOCERTS</TD ><TD >When signing a message the signer's certificate is normally included - with this option it is excluded. This will reduce the size of the signed message but the verifier must have a copy of the signers certificate available locally (passed using the <VAR CLASS="parameter" >extracerts</VAR > to <A HREF="function.openssl-pkcs7-verify.html" ><B CLASS="function" >openssl_pkcs7_verify()</B ></A > for example). </TD ></TR ><TR ><TD >PKCS7_NOATTR</TD ><TD >Normally when a message is signed, a set of attributes are included which include the signing time and the supported symmetric algorithms. With this option they are not included. </TD ></TR ><TR ><TD >PKCS7_DETACHED</TD ><TD >When signing a message, use cleartext signing with the MIME type multipart/signed. This is the default if you do not specify any <VAR CLASS="parameter" >flags</VAR > to <A HREF="function.openssl-pkcs7-sign.html" ><B CLASS="function" >openssl_pkcs7_sign()</B ></A >. If you turn this option off, the message will be signed using opaque signing, which is more resistant to translation by mail relays but cannot be read by mail agents that do not support S/MIME.</TD ></TR ><TR ><TD >PKCS7_NOSIGS</TD ><TD >Don't try and verify the signatures on a message</TD ></TR ></TBODY ></TABLE ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B >These constants were added in 4.0.6.</P ></BLOCKQUOTE ></DIV ></DIV ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Cuprins</B ></DT ><DT ><A HREF="function.openssl-csr-export-to-file.html" >openssl_csr_export_to_file</A > -- Exports a CSR to a file</DT ><DT ><A HREF="function.openssl-csr-export.html" >openssl_csr_export</A > -- Exports a CSR as a string</DT ><DT ><A HREF="function.openssl-csr-new.html" >openssl_csr_new</A > -- Generates a CSR</DT ><DT ><A HREF="function.openssl-csr-sign.html" >openssl_csr_sign</A > -- Sign a CSR with another certificate (or itself) and generate a certificate</DT ><DT ><A HREF="function.openssl-error-string.html" >openssl_error_string</A > -- Return openSSL error message</DT ><DT ><A HREF="function.openssl-free-key.html" >openssl_free_key</A > -- Free key resource</DT ><DT ><A HREF="function.openssl-get-privatekey.html" >openssl_get_privatekey</A > -- Get a private key</DT ><DT ><A HREF="function.openssl-get-publickey.html" >openssl_get_publickey</A > -- Extract public key from certificate and prepare it for use</DT ><DT ><A HREF="function.openssl-open.html" >openssl_open</A > -- Open sealed data</DT ><DT ><A HREF="function.openssl-pkcs7-decrypt.html" >openssl_pkcs7_decrypt</A > -- Decrypts an S/MIME encrypted message</DT ><DT ><A HREF="function.openssl-pkcs7-encrypt.html" >openssl_pkcs7_encrypt</A > -- Encrypt an S/MIME message</DT ><DT ><A HREF="function.openssl-pkcs7-sign.html" >openssl_pkcs7_sign</A > -- sign an S/MIME message</DT ><DT ><A HREF="function.openssl-pkcs7-verify.html" >openssl_pkcs7_verify</A > -- Verifies the signature of an S/MIME signed message</DT ><DT ><A HREF="function.openssl-pkey-export-to-file.html" >openssl_pkey_export_to_file</A > -- Gets an exportable representation of a key into a file </DT ><DT ><A HREF="function.openssl-pkey-export.html" >openssl_pkey_export</A > -- Gets an exportable representation of a key into a string</DT ><DT ><A HREF="function.openssl-pkey-get-private.html" >openssl_pkey_get_private</A > -- Get a private key</DT ><DT ><A HREF="function.openssl-pkey-get-public.html" >openssl_pkey_get_public</A > -- Extract public key from certificate and prepare it for use</DT ><DT ><A HREF="function.openssl-pkey-new.html" >openssl_pkey_new</A > -- Generates a new private key </DT ><DT ><A HREF="function.openssl-private-decrypt.html" >openssl_private_decrypt</A > -- Decrypts data with private key </DT ><DT ><A HREF="function.openssl-private-encrypt.html" >openssl_private_encrypt</A > -- Encrypts data with private key </DT ><DT ><A HREF="function.openssl-public-decrypt.html" >openssl_public_decrypt</A > -- Decrypts data with public key </DT ><DT ><A HREF="function.openssl-public-encrypt.html" >openssl_public_encrypt</A > -- Encrypts data with public key </DT ><DT ><A HREF="function.openssl-seal.html" >openssl_seal</A > -- Seal (encrypt) data</DT ><DT ><A HREF="function.openssl-sign.html" >openssl_sign</A > -- Generate signature</DT ><DT ><A HREF="function.openssl-verify.html" >openssl_verify</A > -- Verify signature</DT ><DT ><A HREF="function.openssl-x509-check-private-key.html" >openssl_x509_check_private_key</A > -- Checks if a private key corresponds to a certificate</DT ><DT ><A HREF="function.openssl-x509-checkpurpose.html" >openssl_x509_checkpurpose</A > -- Verifies if a certificate can be used for a particular purpose</DT ><DT ><A HREF="function.openssl-x509-export-to-file.html" >openssl_x509_export_to_file</A > -- Exports a certificate to file</DT ><DT ><A HREF="function.openssl-x509-export.html" >openssl_x509_export</A > -- Exports a certificate as a string</DT ><DT ><A HREF="function.openssl-x509-free.html" >openssl_x509_free</A > -- Free certificate resource</DT ><DT ><A HREF="function.openssl-x509-parse.html" >openssl_x509_parse</A > -- Parse an X509 certificate and return the information as an array</DT ><DT ><A HREF="function.openssl-x509-read.html" >openssl_x509_read</A > -- Parse an X.509 certificate and return a resource identifier for it</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.ociwritetemporarylob.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.openssl-csr-export-to-file.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >ociwritetemporarylob</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >openssl_csr_export_to_file</TD ></TR ></TABLE ></DIV ></BODY ></HTML >