We now have a youtube channel. Subscribe!

PHP | OpenSSL Functions

PHP OpenSSL Functions

Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP OpenSSL Functions.


OpenSSL is a free open source module that is meant to take care of communications that take place over computer networks. OpenSSL is a tool for Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols.

SSL Certificate

A Secure Sockets Layer (SSL) is used by websites. The SSL certificate takes care of protecting the data between two computers by using encryption. The two computers involved can be the data sharing between the client and server. When you share data like password, credit card details, social security number, home address, it has to be protected and this is taken care of by the SSL certificate. The SSL certificate makes sure that the identity of both computers involved is authenticated for safe connection.

OpenSSL installation in PHP

OpenSSL module is by default added to PHP. You can activate the same by removing the (;) ;extension=php_openssl.dll added at the start of the extension in php.ini. After that restart apache and to confirm if the changes are reflecting save the below code as .php and execute the .php in browser.


You should see the openssl enabled in the browser as shown below -


OpenSSL configuration

The openssl.cnf is the configuration file and has all the default configuration required for openssl to function. To execute openssl, the first thing is that PHP will try to locate the config file. To get the same you will have to add the PHP folder to environment variable.

If you are a Windows user, following below are the steps to setup environment variable for PHP folder -

  1. Right click on My Computer and then go to properties.
  2. Go to Advanced system Settings.
  3. Click on the 'Environment Variables' button.
  4. Edit the path variable and click on the Edit button.
  5. Now add the PHP folder path at the end.
  6. Once you are done, click on the Ok button.
  7. Open your 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_
OPENSSLDIR: "/etc/ssl"

Now PHP will be able to locate the openssl.cnf configuration file.

OpenSSL Functions

The following table below list down all the PHP OpenSSL functions -

Sr.NoFunction & DescriptionVersion

Returns a resource identifier that has new private and public key pair


Returns the private key


Returns the public key


Exports the key to a file


Encrypts the data with the private key


Encrypts the data with public key


Decrypts the data with the public key


Decrypts the data with the private key

In our subsequent tutorials, we are going to be studying about the above list functions.

Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we will be studying about the PHP openssl_pkey_new Function.

Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain