Skip to content
Objective PHP binding of OpenSSL Crypto library
Find file
New pull request
Latest commit 21121e6 @bukka Release 0.2.2
Failed to load latest commit information.
docs Regenerate Crypto.php
examples Remove length parameter from Cipher::getTag
phpc @ a9df7ae Update phpc
tests Unify test names for Cipher::getAlgorithms
utils Add phpc dir to the package_files.php script
.gitignore ignore build files
.gitmodules Add phpc submodule
CREDITS Give me credit
EXPERIMENTAL Initial commit containing ext skeleton Release 0.2.2
LICENSE Fix Copyright years Add Base64 doc entry to readme Release 0.2.0
config.m4 Update config with new files
config.w32 Update config with new files
crypto.c Move check for adding CCM algos to compat section
crypto_base64.c Fix C89 breach in php_crypto_base64_decode_update
crypto_cipher.c Fix compilation warnings
crypto_hash.c Fix proto for MAC construct
crypto_object.c Fix compilation issues
crypto_rand.c Remove Rand::egd
crypto_stream.c Disable CCM mode in stream
package.xml Release 0.2.2
php_crypto.h Release 0.2.2
php_crypto_base64.h Fix Copyright years
php_crypto_cipher.h Add Cipher::setTagLength method
php_crypto_hash.h Add MACException class for invalid key length
php_crypto_object.h Separate all cipher methods and helper
php_crypto_rand.h Remove Rand::egd
php_crypto_stream.h Make stream compat - part 2 (wrapperdata)

PHP OpenSSL Crypto wrapper

The php-crypto is an objective wrapper for OpenSSL Crypto library.



Before starting with installation this extensions, the OpenSSL library has to be installed. It is defaultly installed on the most Linux distribution.

Currently PHP needs to be compiled with OpenSSL extension (--with-openssl). This dependency will be removed in the future.


The RPM package for PHP Crypto is available in Remi's repository:

It is available for Fedora, RHEL and clones (CentOS, SC and others).

After downloading remi-release RPM, the package can be installed by executing following command:

$ sudo yum --enablerepo=remi install php-pecl-crypto


This extension is available on PECL. The package is not currently stable. If the config preferre_state is stable, then the version needs to be specified.

$ sudo pecl install crypto-0.x.y

where x is an installed minor version number and y bug fixing version number.

Manual Installation

It's important to have a git installed as it's necessary for recursive fetch of phpc.

First clone recursively the repository

git clone --recursive

Then go to the created directory and compile the extension. The PHP development package has to be installed (command phpize must be available).

cd php-crypto
sudo make install

Finally the following line needs to be added to php.ini

Be aware that master branch contains a slightly different error handling. You can see examples for more details.


Precompiled binary dll libraries for php-crypto are available on the PECL crypto page.

The php-crypto dll is also available in Jan-E Windows builds on Apache Lounge.


The extension is still in development so the API is not stabilized yet.

All classes are defined in namespace Crypto.

Each base class has an exception class that has the same name and Exception suffix (e.g. Hash class has HashException. The exception classes are subclasses of the PHP Exception class. They define exception code as class constants. Each code also has a different message.

The documentation is devided to sections where can be found documentation of all class methods, constants and other related details:

PHP definition for the classes

The PHP based DocBlock documenation for all classes is generated from the extension code. It can be found in docs/Crypto.php. It can be also used for an IDE autocomplete.


The examples can be found in the example directory.

TODO list

There is lots of features on the TODO list.


The release history can be found

Something went wrong with that request. Please try again.