# Encryption

Encryption library bundled with Zest.

# Configuration

The default encryption adapter in config file Config/App.php is set openssl

WARNING

You should change your encryption key

# Encrypt

You can encrypt string by calling to encrypt method

<?php 
use Zest\Encryption\Encryption;

$encryption = new Encryption('your-key'); // key is optional

//Encrypt the message
$encrypt = $encryption->encrypt("This is a text");

echo $encrypt;
1
2
3
4
5
6
7
8
9

# Decrypt

You can decrypt token by calling decrypt method

<?php 
$encryption = new Encryption('your-key');

//Decrypt the message
$decrypt = $encryption->decrypt($encrypt);	
echo $decrypt;
1
2
3
4
5
6

# Adapter

This Package support two encryption adapter

  • OpenSSL
  • Sodium

# change Adapter

You can pass supported adapter to class like

Use of sodium

<?php 
$encryption = new Encryption('your-key','sodium');
1
2

DANGER

Sodium php extension is required.

Use of openSSL

TIP

The adapter can also be changed from Config/App.php file.

<?php 
$encryption = new Encryption('your-key','openssl');
1
2

DANGER

openSSL php extension is required.

Last Updated: 3/22/2022, 4:20:26 PM