All Projects → paragonie → Halite

paragonie / Halite

Licence: mpl-2.0
High-level cryptography interface powered by libsodium

Projects that are alternatives of or similar to Halite

Nsec
A modern and easy-to-use cryptographic library for .NET Core based on libsodium
Stars: ✭ 217 (-76.74%)
Mutual labels:  cryptography, encryption, libsodium, ed25519, curve25519
Lazysodium Android
An Android implementation of the Libsodium cryptography library. For the lazy dev.
Stars: ✭ 69 (-92.6%)
Mutual labels:  cryptography, encryption, libsodium, argon2
Kryptor
A simple, modern, and secure encryption and signing tool that aims to be a better version of age and Minisign.
Stars: ✭ 267 (-71.38%)
Mutual labels:  argon2, libsodium, ed25519, curve25519
Tweetnacl Js
Port of TweetNaCl cryptographic library to JavaScript
Stars: ✭ 1,176 (+26.05%)
Mutual labels:  authentication, libsodium, ed25519, curve25519
Sodium compat
Pure PHP polyfill for ext/sodium
Stars: ✭ 736 (-21.11%)
Mutual labels:  cryptography, libsodium, ed25519, curve25519
Pgsodium
Modern cryptography for PostgreSQL using libsodium.
Stars: ✭ 202 (-78.35%)
Mutual labels:  cryptography, encryption, libsodium
Securefs
Filesystem in userspace (FUSE) with transparent authenticated encryption
Stars: ✭ 518 (-44.48%)
Mutual labels:  authentication, cryptography, encryption
Fernet Java8
Java 8 implementation of the Fernet Specification
Stars: ✭ 24 (-97.43%)
Mutual labels:  authentication, cryptography, encryption
Rbnacl
Ruby FFI binding to the Networking and Cryptography (NaCl) library (a.k.a. libsodium)
Stars: ✭ 910 (-2.47%)
Mutual labels:  cryptography, libsodium, ed25519
Themis
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.
Stars: ✭ 1,232 (+32.05%)
Mutual labels:  authentication, cryptography, encryption
Ed25519 Dalek
Fast and efficient ed25519 signing and verification in Rust.
Stars: ✭ 383 (-58.95%)
Mutual labels:  cryptography, ed25519, curve25519
Enchive
Encrypted personal archives
Stars: ✭ 527 (-43.52%)
Mutual labels:  encryption, curve25519
Fscrypt
Go tool for managing Linux filesystem encryption
Stars: ✭ 534 (-42.77%)
Mutual labels:  cryptography, argon2
Darkwire.io
End-to-end encrypted instant web chat
Stars: ✭ 594 (-36.33%)
Mutual labels:  cryptography, encryption
Virgil Crypto Php
Virgil PHP Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.
Stars: ✭ 22 (-97.64%)
Mutual labels:  cryptography, encryption
Libsodium Php
The PHP extension for libsodium.
Stars: ✭ 507 (-45.66%)
Mutual labels:  cryptography, libsodium
Age
A simple, modern and secure encryption tool (and Go library) with small explicit keys, no config options, and UNIX-style composability.
Stars: ✭ 9,409 (+908.47%)
Mutual labels:  encryption, curve25519
Libsodium.js
libsodium compiled to Webassembly and pure JavaScript, with convenient wrappers.
Stars: ✭ 665 (-28.72%)
Mutual labels:  cryptography, libsodium
Securitydriven.inferno
✅ .NET crypto done right. Professionally audited.
Stars: ✭ 501 (-46.3%)
Mutual labels:  cryptography, encryption
Sodiumoxide
Sodium Oxide: Fast cryptographic library for Rust (bindings to libsodium)
Stars: ✭ 596 (-36.12%)
Mutual labels:  cryptography, libsodium

Halite

Build Status Latest Stable Version Latest Unstable Version License Downloads Coverage Status

Halite is a high-level cryptography interface that relies on libsodium for all of its underlying cryptography operations.

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.

You can read the Halite Documentation online.

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.

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

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.

PHP libsodium PECL libsodium Support
Halite 4.1 and newer 7.2.0 1.0.15 N/A (standard) ✔️ Active
Halite 4.0 7.2.0 1.0.13 N/A (standard) ✔️ Active
Halite 3 7.0.0 1.0.9 1.0.6 / 2.0.4 ❌ Not Supported
Halite 2 7.0.0 1.0.9 1.0.6 ❌ Not Supported
Halite 1 5.6.0 1.0.6 1.0.2 ❌ Not Supported

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

To install Halite, you first need to install 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 may be helpful.

Once you have the prerequisites installed, install Halite through Composer:

composer require paragonie/halite:^4

Commercial Support for Older Halite Versions

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

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

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

Using Halite in Your Project

Check out the documentation. The basic Halite API is designed for simplicity:

Example: Encrypting and Decrypting a message

First, generate and persist a key exactly once:

<?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:

<?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:

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.

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.

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.

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.

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).

<?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

The solution to this is to make sure libsodium is installed/enabled. See above in this README for more information.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].