PHPackages                             paragonie/halite - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. paragonie/halite

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

paragonie/halite
================

High-level cryptography interface powered by libsodium

v5.1.4(8mo ago)1.2k9.4M—4.5%89[21 issues](https://github.com/paragonie/halite/issues)20MPL-2.0PHPPHP ^8.1CI passing

Since Sep 23Pushed 4mo ago38 watchersCompare

[ Source](https://github.com/paragonie/halite)[ Packagist](https://packagist.org/packages/paragonie/halite)[ Docs](https://github.com/paragonie/halite)[ RSS](/packages/paragonie-halite/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (71)Used By (20)

Halite
======

[](#halite)

[![Build Status](https://github.com/paragonie/halite/actions/workflows/ci.yml/badge.svg)](https://github.com/paragonie/halite/actions)[![Static Analysis](https://github.com/paragonie/halite/actions/workflows/psalm.yml/badge.svg)](https://github.com/paragonie/halite/actions)[![Latest Stable Version](https://camo.githubusercontent.com/af01d4fdea51678dabca07835029b2b13bd3afe155e1638403c442b485caf8ea/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f68616c6974652f762f737461626c65)](https://packagist.org/packages/paragonie/halite)[![Latest Unstable Version](https://camo.githubusercontent.com/acdc94cfaebf39c174490ec83ef439c18d650a2f5a686706acb514f772ed960b/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f68616c6974652f762f756e737461626c65)](https://packagist.org/packages/paragonie/halite)[![License](https://camo.githubusercontent.com/09cae15cd4ee304bbbc275fc255b428b0667b5ce4c03f1514605ac63a3aa5802/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f68616c6974652f6c6963656e7365)](https://packagist.org/packages/paragonie/halite)[![Downloads](https://camo.githubusercontent.com/18ff09ce1ea6b8279b034287add5d0cd656e6bf86c999a7adf7f54cc8b1b57f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70617261676f6e69652f68616c6974652e737667)](https://packagist.org/packages/paragonie/halite)[![Coverage Status](https://raw.githubusercontent.com/paragonie/halite/refs/heads/image-data/coverage.svg)](https://github.com/paragonie/halite/actions/workflows/coverage.yml)

**Halite** is a high-level cryptography interface that relies on [libsodium](https://pecl.php.net/package/libsodium)for all of its underlying cryptography operations.

Halite was created by [Paragon Initiative Enterprises](https://paragonie.com) as a result of our continued efforts to improve the ecosystem and make [cryptography in PHP](https://paragonie.com/blog/2015/09/state-cryptography-in-php)safer and easier to implement.

> You can read the [**Halite Documentation**](https://github.com/paragonie/halite/tree/master/doc) online.

Halite is released under Mozilla Public License 2.0. [Commercial licenses are available](https://paragonie.com/contact)from Paragon Initiative Enterprises if you wish to extend Halite without making your derivative works available under the terms of the MPL.

If you are satisfied with the terms of MPL software for backend web applications but would like to purchase a support contract for your application that uses Halite, those are also offered by Paragon Initiative Enterprises.

**Important:** Earlier versions of Halite were available under the GNU Public License version 3 (GPLv3). Only Halite 4.0.1 and newer are available under the Mozilla Public License terms.

Installing Halite
-----------------

[](#installing-halite)

Before you can use Halite, you must choose a version that fits the requirements of your project. The differences between the requirements for the available versions of Halite are briefly highlighted below.

PHPlibsodiumPECL libsodiumSupportHalite 5.1 and newer8.1.01.0.18N/A (standard)✔️ ActiveHalite 5.0.x8.0.01.0.18N/A (standard)✔️ Active[Halite 4.1+](https://github.com/paragonie/halite/tree/v4.x)7.2.01.0.15N/A (standard)❌ Not Supported[Halite 4.0](https://github.com/paragonie/halite/tree/v4.0)7.2.01.0.13N/A (standard)❌ Not Supported[Halite 3](https://github.com/paragonie/halite/tree/v3.x)7.0.01.0.91.0.6 / 2.0.4❌ Not Supported[Halite 2](https://github.com/paragonie/halite/tree/v2.2)7.0.01.0.91.0.6❌ Not Supported[Halite 1](https://github.com/paragonie/halite/tree/v1.x)5.6.01.0.61.0.2❌ Not SupportedNote: Halite 5.0.x works on PHP 8.0, but performance is worse than on PHP 8.1.

If you need a version of Halite before 5.1, see the documentation relevant to that particular branch.

**To install Halite, you first need to [install libsodium](https://paragonie.com/book/pecl-libsodium/read/00-intro.md#installing-libsodium).**You may or may not need the PHP extension. For most people, this means running...

```
sudo apt-get install php7.2-sodium

```

...or an equivalent command for your operating system and PHP version.

If you're stuck, [this step-by-step guide contributed by @aolko](doc/Install-Guides/Ubuntu.md) may be helpful.

Once you have the prerequisites installed, install Halite through [Composer](https://getcomposer.org/doc/00-intro.md):

```
composer require paragonie/halite:^5

```

### Commercial Support for Older Halite Versions

[](#commercial-support-for-older-halite-versions)

Free (gratis) support for Halite only extends to the most recent major version (currently 5).

If your company requires support for an older version of Halite, [contact Paragon Initiative Enterprises](https://paragonie.com/contact) to inquire about commercial support options.

If you need an easy way to migrate from older versions of Halite, check out [halite-legacy](https://github.com/paragonie/halite-legacy).

Using Halite in Your Project
----------------------------

[](#using-halite-in-your-project)

Check out the [documentation](doc). The basic Halite API is designed for simplicity:

- Encryption
    - Symmetric
        - `Symmetric\Crypto::encrypt`([`HiddenString`](doc/Classes/HiddenString.md), [`EncryptionKey`](doc/Classes/Symmetric/EncryptionKey.md)): `string`
        - `Symmetric\Crypto::encryptWithAD`([`HiddenString`](doc/Classes/HiddenString.md), [`EncryptionKey`](doc/Classes/Symmetric/EncryptionKey.md), `string`): `string`
        - `Symmetric\Crypto::decrypt`(`string`, [`EncryptionKey`](doc/Classes/Symmetric/EncryptionKey.md)): [`HiddenString`](doc/Classes/HiddenString.md)
        - `Symmetric\Crypto::decryptWithAD`(`string`, [`EncryptionKey`](doc/Classes/Symmetric/EncryptionKey.md), `string`): [`HiddenString`](doc/Classes/HiddenString.md)
    - Asymmetric
        - Anonymous
            - `Asymmetric\Crypto::seal`([`HiddenString`](doc/Classes/HiddenString.md), [`EncryptionPublicKey`](doc/Classes/Asymmetric/EncryptionPublicKey.md)): `string`
            - `Asymmetric\Crypto::unseal`(`string`, [`EncryptionSecretKey`](doc/Classes/Asymmetric/EncryptionSecretKey.md)): [`HiddenString`](doc/Classes/HiddenString.md)
        - Authenticated
            - `Asymmetric\Crypto::encrypt`([`HiddenString`](doc/Classes/HiddenString.md), [`EncryptionSecretKey`](doc/Classes/Asymmetric/EncryptionSecretKey.md), [`EncryptionPublicKey`](doc/Classes/Asymmetric/EncryptionPublicKey.md)): `string`
            - `Asymmetric\Crypto::encryptWithAD`([`HiddenString`](doc/Classes/HiddenString.md), [`EncryptionSecretKey`](doc/Classes/Asymmetric/EncryptionSecretKey.md), [`EncryptionPublicKey`](doc/Classes/Asymmetric/EncryptionPublicKey.md), `string`): `string`
            - `Asymmetric\Crypto::decrypt`(`string`, [`EncryptionSecretKey`](doc/Classes/Asymmetric/EncryptionSecretKey.md), [`EncryptionPublicKey`](doc/Classes/Asymmetric/EncryptionPublicKey.md)): [`HiddenString`](doc/Classes/HiddenString.md)
            - `Asymmetric\Crypto::decryptWithAD`(`string`, [`EncryptionSecretKey`](doc/Classes/Asymmetric/EncryptionSecretKey.md), [`EncryptionPublicKey`](doc/Classes/Asymmetric/EncryptionPublicKey.md), `string`): [`HiddenString`](doc/Classes/HiddenString.md)
- Authentication
    - Symmetric
        - `Symmetric\Crypto::authenticate`(`string`, [`AuthenticationKey`](doc/Classes/Symmetric/AuthenticationKey.md)): `string`
        - `Symmetric\Crypto::verify`(`string`, [`AuthenticationKey`](doc/Classes/Symmetric/AuthenticationKey.md), `string`): `bool`
    - Asymmetric
        - `Asymmetric\Crypto::sign`(`string`, [`SignatureSecretKey`](doc/Classes/Asymmetric/SignatureSecretKey.md)): `string`
        - `Asymmetric\Crypto::verify`(`string`, [`SignaturePublicKey`](doc/Classes/Asymmetric/SignaturePublicKey.md), `string`): `bool`

### Example: Encrypting and Decrypting a message

[](#example-encrypting-and-decrypting-a-message)

First, generate and persist a key exactly once:

```
