2017 © Pedro Peláez
 

library halite

High-level cryptography interface powered by libsodium

image

paragonie/halite

High-level cryptography interface powered by libsodium

  • Monday, May 7, 2018
  • by paragonie-scott
  • Repository
  • 45 Watchers
  • 718 Stars
  • 129,872 Installations
  • PHP
  • 23 Dependents
  • 8 Suggesters
  • 47 Forks
  • 8 Open issues
  • 59 Versions
  • 22 % Grown

The README.md

Halite

Build Status Static Analysis Latest Stable Version Latest Unstable Version License Downloads Coverage Status, (*1)

Halite is a high-level cryptography interface that relies on libsodium for all of its underlying cryptography operations., (*2)

Halite was created by Paragon Initiative Enterprises as a result of our continued efforts to improve the ecosystem and make cryptography in PHP safer and easier to implement., (*3)

You can read the Halite Documentation online., (*4)

Halite is released under Mozilla Public License 2.0. Commercial licenses are available from Paragon Initiative Enterprises if you wish to extend Halite without making your derivative works available under the terms of the MPL., (*5)

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., (*6)

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., (*7)

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., (*8)

PHP libsodium PECL libsodium Support
Halite 5.1 and newer 8.1.0 1.0.18 N/A (standard) :heavy_check_mark: Active
Halite 5.0.x 8.0.0 1.0.18 N/A (standard) :heavy_check_mark: Active
Halite 4.1+ 7.2.0 1.0.15 N/A (standard) :x: Not Supported
Halite 4.0 7.2.0 1.0.13 N/A (standard) :x: Not Supported
Halite 3 7.0.0 1.0.9 1.0.6 / 2.0.4 :x: Not Supported
Halite 2 7.0.0 1.0.9 1.0.6 :x: Not Supported
Halite 1 5.6.0 1.0.6 1.0.2 :x: Not Supported

Note: Halite 5.0.x works on PHP 8.0, but performance is worse than on PHP 8.1., (*9)

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

To install Halite, you first need to install libsodium. You may or may not need the PHP extension. For most people, this means running..., (*11)

sudo apt-get install php7.2-sodium

...or an equivalent command for your operating system and PHP version., (*12)

If you're stuck, this step-by-step guide contributed by @aolko may be helpful., (*13)

Once you have the prerequisites installed, install Halite through Composer:, (*14)

composer require paragonie/halite:^5

Commercial Support for Older Halite Versions

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

If your company requires support for an older version of Halite, contact Paragon Initiative Enterprises to inquire about commercial support options., (*16)

If you need an easy way to migrate from older versions of Halite, check out halite-legacy., (*17)

Using Halite in Your Project

Check out the documentation. The basic Halite API is designed for simplicity:, (*18)

Example: Encrypting and Decrypting a message

First, generate and persist a key exactly once:, (*19)

<?php
use ParagonIE\Halite\KeyFactory;

$encKey = KeyFactory::generateEncryptionKey();
KeyFactory::save($encKey, '/path/outside/webroot/encryption.key');

And then you can encrypt/decrypt messages like so:, (*20)

<?php
use ParagonIE\Halite\KeyFactory;
use ParagonIE\Halite\Symmetric\Crypto as Symmetric;
use ParagonIE\HiddenString\HiddenString;

$encryptionKey = KeyFactory::loadEncryptionKey('/path/outside/webroot/encryption.key');

$message = new HiddenString('This is a confidential message for your eyes only.');
$ciphertext = Symmetric::encrypt($message, $encryptionKey);

$decrypted = Symmetric::decrypt($ciphertext, $encryptionKey);

var_dump($decrypted->getString() === $message->getString()); // bool(true)

This should produce something similar to:, (*21)

MUIDAEpQznohvNlQ-ZRk-ZZ59Mmox75D_FgAIrXY2cUfStoeL-GIeAe0m-uaeURQdPsVmc5XxRw3-2x5ZAsZH_es37qqFuLFjUI-XK9uG0s30YTsorWfpHdbnqzhRuUOI09c-cKrfMQkNBNm0dDDwZazjTC48zWikRHSHXg8NXerVDebzng1aufc_S-osI_zQuLbZDODujEnpbPZhMMcm4-SWuyVXcBPdGZolJyT

Cryptographic Keys in Halite

Important: Halite works with Key objects, not strings., (*22)

If you attempt to echo a key object, you will get an empty string rather than its contents. If you attempt to var_dump() a key object, you will just get some facts about the type of key it is., (*23)

You must invoke $obj->getRawKeyMaterial() explicitly if you want to inspect a key's raw binary contents. This is not recommended for most use cases., (*24)

Example: Generating a key from a password

<?php
use ParagonIE\Halite\KeyFactory;
use ParagonIE\HiddenString\HiddenString;

$passwd = new HiddenString('correct horse battery staple');
// Use random_bytes(16); to generate the salt:
$salt = "\xdd\x7b\x1e\x38\x75\x9f\x72\x86\x0a\xe9\xc8\x58\xf6\x16\x0d\x3b";

$encryptionKey = KeyFactory::deriveEncryptionKey($passwd, $salt);

A key derived from a password can be used in place of one randomly generated., (*25)

Example: Encrypting a large file on a system with low memory

Halite includes a file cryptography class that utilizes a streaming API to allow large files (e.g. gigabytes) be encrypted on a system with very little available memory (i.e. less than 8 MB)., (*26)

<?php
use ParagonIE\Halite\File;
use ParagonIE\Halite\KeyFactory;

$encryptionKey = KeyFactory::loadEncryptionKey('/path/outside/webroot/encryption.key');

File::encrypt('input.txt', 'output.txt', $encryptionKey);

Common Support Issues

Uncaught SodiumException: Cannot Wipe Memory

PHP Fatal error: Uncaught SodiumException: This is not implemented, as it is not possible to securely wipe memory from PHP, (*27)

The solution to this is to make sure libsodium is installed/enabled. See above in this README for more information., (*28)

Support Contracts

If your company uses this library in their products or services, you may be interested in purchasing a support contract from Paragon Initiative Enterprises., (*29)

The Versions

07/05 2018

dev-extract-hiddenstring

dev-extract-hiddenstring https://github.com/paragonie/halite

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

27/03 2018

dev-master

9999999-dev https://github.com/paragonie/halite

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3 MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

27/03 2018

dev-psalm-redundant

dev-psalm-redundant https://github.com/paragonie/halite

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

27/03 2018

v4.4.2

4.4.2.0 https://github.com/paragonie/halite

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

27/03 2018

v3.x-dev

3.9999999.9999999.9999999-dev

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3 GPL-3.0-or-later

The Requires

 

The Development Requires

27/03 2018

v3.4.1

3.4.1.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL-3.0-or-later

The Requires

 

The Development Requires

27/02 2018

v4.4.1

4.4.1.0 https://github.com/paragonie/halite

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

04/02 2018

v4.4.0

4.4.0.0 https://github.com/paragonie/halite

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

04/02 2018

v4.0.x-dev

4.0.9999999.9999999-dev

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

30/01 2018

v4.0.3

4.0.3.0

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

30/01 2018

v4.3.1

4.3.1.0 https://github.com/paragonie/halite

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

29/01 2018

v2.2.x-dev

2.2.9999999.9999999-dev

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3 GPL-3.0-or-later

The Requires

  • php ^7.0.0
  • ext-libsodium ^1.0.6

 

29/01 2018

v1.x-dev

1.9999999.9999999.9999999-dev

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3 GPL-3.0-or-later

The Requires

 

The Development Requires

29/01 2018

v3.4.0

3.4.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

 

The Development Requires

26/01 2018

v4.3.0

4.3.0.0 https://github.com/paragonie/halite

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

15/01 2018

v4.2.0

4.2.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

05/01 2018

v4.1.0

4.1.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake ext-sodium

08/12 2017

v4.0.2

4.0.2.0

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

password encryption cryptography hashing libsodium signatures public-key curve25519 x25519 ed25519 xsalsa20 blake2b sodium argon2 blake2 argon2i blake

19/10 2017

v4.0.1

4.0.1.0

High-level cryptography interface powered by libsodium

  Sources   Download

MPL-2.0

The Requires

 

The Development Requires

01/10 2017

v1.6.0

1.6.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

 

The Development Requires

16/09 2017

v4.0.0

4.0.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

 

The Development Requires

19/08 2017

v3.3.0

3.3.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

 

The Development Requires

08/12 2016

v3.2.0

3.2.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

 

27/10 2016

v3.1.1

3.1.1.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

 

22/08 2016

v2.2.0

2.2.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^7.0.0
  • ext-libsodium ^1.0.6

 

22/08 2016

v3.1.0

3.1.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

 

30/07 2016

v3.0.0

3.0.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

 

29/07 2016

dev-stable

dev-stable

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.2

 

29/07 2016

v1.5.1

1.5.1.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.2

 

29/07 2016

v2.1.x-dev

2.1.9999999.9999999-dev

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^7.0.0
  • ext-libsodium ^1.0.6

 

29/07 2016

v2.1.3

2.1.3.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^7.0.0
  • ext-libsodium ^1.0.6

 

11/07 2016

v2.1.2

2.1.2.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^7.0.0
  • ext-libsodium ^1.0.6

 

15/05 2016

v2.1.1

2.1.1.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^7.0.0
  • ext-libsodium ^1.0.6

 

07/05 2016

v2.1.0

2.1.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^7.0.0
  • ext-libsodium ^1.0.6

 

21/04 2016

v2.0.x-dev

2.0.9999999.9999999-dev

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^7.0.0
  • ext-libsodium ^1.0.3

 

21/04 2016

v2.0.1

2.0.1.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^7.0.0
  • ext-libsodium ^1.0.3

 

15/04 2016

dev-mad-science

dev-mad-science

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^7.0.0
  • ext-libsodium ^1.0.3

 

04/04 2016

v2.0.0

2.0.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^7.0.0
  • ext-libsodium ^1.0.3

 

08/03 2016

v1.5.0

1.5.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.2

 

17/02 2016

1.4.0

1.4.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.2

 

17/01 2016

1.3.2

1.3.2.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.2

 

14/01 2016

1.3.1

1.3.1.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.2

 

30/12 2015

1.3.0

1.3.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.2

 

14/11 2015

1.2.0

1.2.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.2

 

06/11 2015

1.1.0

1.1.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.2

 

06/11 2015

1.0.0

1.0.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.2

 

03/11 2015

0.8.1

0.8.1.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.1

 

02/11 2015

0.8.0

0.8.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.1

 

30/10 2015

0.7.0

0.7.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.1

 

26/10 2015

0.6.0

0.6.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0.1

 

21/10 2015

0.5.3

0.5.3.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0

 

17/10 2015

0.5.2

0.5.2.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0

 

15/10 2015

0.5.1

0.5.1.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0

 

14/10 2015

0.5.0

0.5.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0

 

14/10 2015

0.4.0

0.4.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0

 

12/10 2015

0.3.2

0.3.2.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0 || ^7.0.0
  • ext-libsodium ^1.0

 

09/10 2015

0.3.1

0.3.1.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • php ^5.6.0
  • ext-libsodium ^1.0

 

08/10 2015

0.3.0

0.3.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • ext-libsodium ^1.0

 

23/09 2015

0.1.0

0.1.0.0

High-level cryptography interface powered by libsodium

  Sources   Download

GPL3

The Requires

  • ext-libsodium ^1.0