English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Функции OpenSSL PHP

What is OpenSSL?

OpenSSL is a free open-source module designed to handle communication over computer networks. OpenSSL is a tool for transport layer security (TLS) and secure sockets layer (SSL) protocols.

What is an SSL certificate?

Websites use secure sockets layer (that is, SSL). SSL certificates are responsible for encrypting data between two computers. The two computers involved can be data sharing between client and server. When you share data such as passwords, credit card details, home address, social security numbers, etc., they must be protected, and SSL certificates will protect them. SSL certificates ensure that the identity of the two computers involved is authenticated to ensure a secure connection.

OpenSSL installation in PHP

By default, the OpenSSL module has been added to PHP. You can remove it by deleting it in php.ini; extension = php_openssl.dllStartThe semicolon (;) to enable them. After that, restart apache and confirm that the changes have taken effect, then save the following code as .php and execute .php in the browser.

<?php
   phpinfo();
?>
Test to see if the < / >

You should see OpenSSL enabled in your browser as follows:

OpenSSL configuration

openssl.cnf is a configuration file that contains all the default configurations required for OpenSSL to work. To run OpenSSL, the first thing php will try to find is the configuration file. To get the same file, you must add the php folder to the environment variable.

If you are a Windows user, please follow the steps below to set the environment variable for the php folder:

1. Right-click on My Computer and go to Properties.

2. Go to Advanced System Settings.

3. Click the 'Environment Variables' button.

4. Edit the path variable and then click the 'Edit' button.

5. Now add the Php folder path at the end. I am using xampp, and my php folder is c:\xampp\php;.

6. After completion, click the OK button.

7. Now open the Command Prompt and enter the command: openssl version -a.

C:\Windows\system32>openssl version -a
OpenSSL 1.0.2l 25 May 2017
built on: reproducible build, date unspecified
platform: mingw64
options: bn(64,64) rc4(16x,int) des(idx,cisc,2,long) idea(int) blowfish(idx)
compiler: x86_64-w64-mingw32-gcc -I. -I.. -I../include -D_WINDLL -DOPENSSL_PIC
-DOPENSSL_THREADS -D_MT -DDSO_WIN32 -static-libgcc -DL_ENDIAN -O3 -Wall -DWIN32_
LEAN_AND_MEAN -DUNICODE -D_UNICODE -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DO
PENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSH
A512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
 -DECP_NISTZ256_ASM
OPENSSLDIR: " /etc/ssl "

Теперь php сможет найти файл конфигурации openssl.cnf.

Функции OpenSSL

В таблице перечислены все функции, связанные с PHP OpenSSL. "Версия" означает earliest версия PHP, которая поддерживает функциональность функции.

НомерФункцияОписание
Версия
1openssl_pkey_new()Возврат идентификатора ресурса с новым паром частного и публичного ключей5.0.0
2openssl_pkey_get_private()Возврат частного ключа5.0.0
3openssl_pkey_get_public()Возврат публичного ключа5.0.0
4openssl_pkey_export_to_file()Экспорт ключа в файл5.0.0
5openssl_private_encrypt()Использование частного ключа для шифрования данных5.0.0
6openssl_public_encrypt()

Использование публичного ключа для шифрования данных

5.0.0
7openssl_public_decrypt()Использование публичного ключа для расшифровки данных5.0.0
8openssl_private_decrypt()Использование частного ключа для расшифровки данных5.0.0