internetpixels / sodium-encryption
Encrypt and decrypt data with this easy to use PHP encryption library
Installs: 3 005
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 0
Open Issues: 2
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2025-02-16 17:41:58 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.
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);