PHPackages                             dwgebler/encryption - 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. dwgebler/encryption

ActiveLibrary[Security](/categories/security)

dwgebler/encryption
===================

Encryption wrapper for PHP which uses libsodium to provide a simple API for symmetric and asymmetric encryption, decryption, digital signing and message authentication.

1.1.0(3y ago)316.9k—0%4[1 PRs](https://github.com/dwgebler/php-encryption/pulls)MITPHPPHP &gt;=7.2.0

Since Apr 5Pushed 3y ago3 watchersCompare

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

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

PHP Encryption
==============

[](#php-encryption)

[![Build Status!](https://camo.githubusercontent.com/3e5843dbee840e4aecc870498b66261cc5965adac40381459ac0c82b7b97c17a/68747470733a2f2f6170702e7472617669732d63692e636f6d2f64776765626c65722f7068702d656e6372797074696f6e2e7376673f746f6b656e3d756a344866586d3577714a585675504164393834266272616e63683d6d6173746572)](https://camo.githubusercontent.com/3e5843dbee840e4aecc870498b66261cc5965adac40381459ac0c82b7b97c17a/68747470733a2f2f6170702e7472617669732d63692e636f6d2f64776765626c65722f7068702d656e6372797074696f6e2e7376673f746f6b656e3d756a344866586d3577714a585675504164393834266272616e63683d6d6173746572)

A cryptography API wrapping the Sodium library, providing a simple object interface for symmetrical and asymmetrical encryption, decryption, digital signing and message authentication.

The `Encryption` class is able to generate secrets and keypairs, encrypt and decrypt data, sign and verify data, and generate and verify digital signatures.

Encrypted messages are returned base64 encoded, while keys and secrets are returned as hexadecimal strings.

The transformation of these to and from binary data makes use of the `sodium_*` timing-safe functions.

All underlying cryptography is performed using the [Sodium](https://www.php.net/manual/en/book.sodium.php) library.

This library requires PHP 7.2 or higher with `libsodium` installed (this is bundled with PHP 7.2 or above, so you probably already have it).

Installation
------------

[](#installation)

Install via Composer

```
composer require dwgebler/encryption
```

Usage
-----

[](#usage)

For a quick start, see the included `demo.php` file.

Create an instance of the Encryption class.

```
