Sodium Compat is a pure PHP polyfill for the Sodium cryptography library (libsodium), a core extension in PHP 7.2.0+ and otherwise available in PECL.
If you have the PHP extension installed, Sodium Compat will opportunistically and transparently use the PHP extension instead of our implementation.
sodium_compat v1.21.0 was the last v1.x release from the master branch. From now
on, all future releases that support PHP 5.2 - 8.0 and 32-bit integers will be
in the v1.x
branch.
Newer versions of sodium_compat (i.e., v2.0.0) will continue to live in the master branch, unless a new major version is needed. The goal of this work is to improve code readability and performance, while reducing boilerplate code.
When in doubt, refer to the README file in the master branch for the latest in version information.
sodium_compat version | PHP versions supported | 32-bit support? | Branch |
---|---|---|---|
v1.x.y |
5.2.4 - LATEST | YES | v1.x |
v2.x.y |
8.1 - LATEST | NO | master |
If you need 32-bit PHP support (PHP_INT_SIZE == 4
), continue using sodium_compat v1.x.
If you want improved performance and smaller dependencies, use v2.x.
We recommend libraries and frameworks set a Composer version constraint as follows:
{
"require": {
/* ... */
"paragonie/sodium_compat": ">= 1"
/* ... */
}
}
Applications should, conversely, specify the actual version that matters to them and their deployments.
This cryptography library has not been formally audited by an independent third party that specializes in cryptography or cryptanalysis.
If you require such an audit before you can use sodium_compat in your projects
and have the funds for such an audit, please open an issue or contact
security at paragonie dot com
so we can help get the ball rolling.
However, sodium_compat has been adopted by high profile open source projects, such as Joomla! and Magento. Furthermore, sodium_compat was developed by Paragon Initiative Enterprises, a company that specializes in secure PHP development and PHP cryptography, and has been informally reviewed by many other security experts who also specialize in PHP.
If you'd like to learn more about the defensive security measures we've taken to prevent sodium_compat from being a source of vulnerability in your systems, please read Cryptographically Secure PHP Development.
If you're using Composer:
composer require paragonie/sodium_compat
If you're not using Composer, download a release tarball
(which should be signed with our GnuPG public key), extract
its contents, then include our autoload.php
script in your project.
<?php
require_once "/path/to/sodium_compat/autoload.php";
Since version 1.3.0, sodium_compat releases include a PHP Archive (.phar file) and associated GPG signature. First, download both files and verify them with our GPG public key, like so: