PHPackages                             guazi/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. [Security](/categories/security)
4. /
5. guazi/halite

ActiveLibrary[Security](/categories/security)

guazi/halite
============

High-level cryptography interface powered by libsodium

v3.2.0(9y ago)0544GPL3PHPPHP ^7

Since Sep 23Pushed 9y ago1 watchersCompare

[ Source](https://github.com/totoleo/halite)[ Packagist](https://packagist.org/packages/guazi/halite)[ RSS](/packages/guazi-halite/feed)WikiDiscussions stable Synced 3w ago

READMEChangelog (1)Dependencies (1)Versions (43)Used By (0)

Halite
======

[](#halite)

[![Build Status](https://camo.githubusercontent.com/dfc997a91164d817ba52b68247a056fe33333399e82e2833f25e00bece086734/68747470733a2f2f7472617669732d63692e6f72672f746f746f6c656f2f68616c6974652e7376673f6272616e63683d737461626c65)](https://travis-ci.org/totoleo/halite)[![Latest Stable Version](https://camo.githubusercontent.com/af01d4fdea51678dabca07835029b2b13bd3afe155e1638403c442b485caf8ea/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f68616c6974652f762f737461626c65)](https://packagist.org/packages/guazi/halite)[![Latest Unstable Version](https://camo.githubusercontent.com/acdc94cfaebf39c174490ec83ef439c18d650a2f5a686706acb514f772ed960b/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f68616c6974652f762f756e737461626c65)](https://packagist.org/packages/guazi/halite)[![License](https://camo.githubusercontent.com/09cae15cd4ee304bbbc275fc255b428b0667b5ce4c03f1514605ac63a3aa5802/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f68616c6974652f6c6963656e7365)](https://packagist.org/packages/guazi/halite)

> **Note**: This is the version 1 branch. Please upgrade to a newer version as soon as possible.

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.

It's released under the GPLv3 license. [Commercial licenses are available](https://paragonie.com/contact) from Paragon Initiative Enterprises if you wish to implement Halite in an application without making your source code available under a GPL-compatible license.

Using Halite in Your Applications
---------------------------------

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

### Step 1: Installing libsodium

[](#step-1-installing-libsodium)

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 libsodiumHalite 2+7.0.01.0.91.0.6Halite 15.5.91.0.61.0.2If you plan to use Halite 1, or your distribution has the necessary version already, then you should be able to [install a precompiled libsodium](https://paragonie.com/book/pecl-libsodium/read/00-intro.md#installing-libsodium)package.

### Step 2: Installing the PECL libsodium extension

[](#step-2-installing-the-pecl-libsodium-extension)

**Important Note**: It is important that this step is repeated every time that a different version of libsodium is installed. The resulting PECL libsodium extension is version dependent of the currently installed libsodium.

Installation instructions for the PECL libsodium extension can be found in the [PECL libsodium book](https://paragonie.com/book/pecl-libsodium/read/00-intro.md#installing-extension)on the Paragon Initiative Enterprises website.

### Step 3: Use Composer to install Halite

[](#step-3-use-composer-to-install-halite)

The last step required to use Halite is to install it using Composer.

For the latest version of Halite:

```
composer require guazi/halite

```

Or for older versions of Halite, specify the version number:

```
composer require guazi/halite:^v1

```

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`(`string`, [`EncryptionKey`](doc/Classes/Symmetric/EncryptionKey.md), `bool?`): `string`
        - `Symmetric\Crypto::decrypt`(`string`, [`EncryptionKey`](doc/Classes/Symmetric/EncryptionKey.md), `bool?`): `string`
    - Asymmetric
        - Anonymous
            - `Asymmetric\Crypto::seal`(`string`, [`EncryptionPublicKey`](doc/Classes/Asymmetric/EncryptionPublicKey.md), `bool?`): `string`
            - `Asymmetric\Crypto::unseal`(`string`, [`EncryptionSecretKey`](doc/Classes/Asymmetric/EncryptionSecretKey.md), `bool?`): `string`
        - Authenticated
            - `Asymmetric\Crypto::encrypt`(`string`, [`EncryptionSecretKey`](doc/Classes/Asymmetric/EncryptionSecretKey.md), [`EncryptionPublicKey`](doc/Classes/Asymmetric/EncryptionPublicKey.md), `bool?`): `string`
            - `Asymmetric\Crypto::decrypt`(`string`, [`EncryptionSecretKey`](doc/Classes/Asymmetric/EncryptionSecretKey.md), [`EncryptionPublicKey`](doc/Classes/Asymmetric/EncryptionPublicKey.md), `bool?`): `string`
- Authentication
    - Symmetric
        - `Symmetric\Crypto::authenticate`(`string`, [`AuthenticationKey`](doc/Classes/Symmetric/AuthenticationKey.md), `bool?`): `string`
        - `Symmetric\Crypto::verify`(`string`, [`AuthenticationKey`](doc/Classes/Symmetric/AuthenticationKey.md), `string`, `bool?`): `bool`
    - Asymmetric
        - `Asymmetric\Crypto::sign`(`string`, [`SignatureSecretKey`](doc/Classes/Asymmetric/SignatureSecretKey.md), `bool?`): `string`
        - `Asymmetric\Crypto::verify`(`string`, [`SignaturePublicKey`](doc/Classes/Asymmetric/SignaturePublicKey.md), `string`, `bool?`): `bool`

### Example: Encrypting and Decrypting a message

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

First, generate and persist a key exactly once:

```
