πŸ”Encryption

This controller is made for encrypting and decrypting values for storage. You can control the salt and key to use as encryption handler.

Settings

You can add two fields to specify a specific key and salt for encryption:

NAN_DEFAULT_KEY=
NAN_DEFAULT_SALT=

If not set it will use the APP_KEY as key and change it a bit for a salt.

Changing the key and/or salt will make previously encrypted values unreadable for the decrypt function!!

Start of by importing the controller where you are using it

use NaN\NanGeneralController\Controllers\EncryptionController;

Encryption

A function for encrypting data for storage.

Example:

$phone_number = '+31612345678';
$EncryptionController = new EncryptionController();
$encrypted = $EncryptionController->encrypt($phone_number);

Tip: Set the debug paramater to true to see what the validation fails on

$ValidationController->validateEmail($email, true);

// invalid_mx_or_a_record
// invalid_domain
// invalid_pregmatch_validate
// invalid_filter_validate

Descrypt

A way to decrypt the encrypted values. This only works on values encrypted with the same key and salt as you are trying to decrypt.

Example:

$number_value = '9H92n....eExMQT0FUDZq=';
$ValidationController = new ValidationController();
$phone_number = $ValidationController->decrypt($number_value, true);    

Dummy

Get a dummy example of the decrypted value for displaying purposes. It only shows the first 3 chars and adds a '●'-char for every other character in the string.

$api_key = 'Hn929....MUDZqQT0eExF=';
$ValidationController = new ValidationController();
$api_key = $ValidationController->decrypt($api_key, true);    
$api_key_to_show = $ValidationController->getDummy($api_key, true);

Contains dummy character

Function to check if a string contains dummy characters. This is so you can prevent the saving of a submitted dummy-ised value

$submitted_value = 'jes●●●●●●●●●●●●●●●●●●●';
$EncryptionController = new EncryptionController();
if (!$EncryptionController->containsDummyCharacter($submitted_value)){
    // Do stuff
}

Decrypt object values

Function to decrypt a encrypted object. For example when getting a entry from a database, you can decrypt the object at once

$user = User::find(1);
$EncryptionController = new EncryptionController();
        $user = $EncryptionController->decryptObjectValues($user);

Last updated