internetpixels/sodium-encryption

There is no license information available for the latest version (1.0.0) of this package.

Encrypt and decrypt data with this easy to use PHP encryption library

1.0.0 2018-06-15 06:41 UTC

This package is auto-updated.

Last update: 2024-04-16 16:00:50 UTC


README

Protect your data and secure every field in your entities with this tiny encryption library!

This is a open-source library. Please consider a link to this repository when you're actively using it.

License Build Status Maintainability

Install with composer

This small encryption/decryption library can be required by using composer. Please use the following command:

composer require internetpixels/sodium-encryption

Setup the TokenManager

You have to set the secret and public tokens once. Those keys are not allowed to change overtime!

<?php
// Update the keys (create a new unique keypair)!
\InternetPixels\SodiumEncryption\EncryptionManager::setKeys(
    '1d17336ba7b2cec7dc8ec788e78ebf835d9f85cfc414275e92fd8e3ae5d6d2b6',
    'b88fc95850eec82492e9f0616cfeb69b9205735e34f5ce5e83d681eb38147d57'
);

Encrypt a field

We advise you to create a unique nonce per entity (use the EncryptionManager::generateNonce() method). You'll have to save the nonce with your data too, because it will be used when you want to decrypt the data again.

<?php
$string = 'This is my default text string with 88 numbers!';
$nonce = EncryptionManager::generateNonce();

$encrypted = EncryptionManager::encrypt($string, $nonce);

Decrypt a field

In order to decrypt a field, you'll need the encrypted string and the nonce.

<?php
$string = EncryptionManager::decrypt($encrypted, $nonce);