snappdoctor/drcoder

1.0.3 2021-01-04 17:07 UTC

This package is auto-updated.

Last update: 2024-05-05 00:59:32 UTC


README

68747470733a2f2f736e6170702e646f63746f722f7374617469632f6d656469612f736e61705f6865616465722e38316464613737372e706e67

Total Downloads Latest Stable Version License License

SnappDoctor Encoder package

This package handle and encode/decode any data. The package provide some drivers to encode/decode the data that will explain below.

Installation.

Before anything, The developer has to know witch Encoder class uses the built-in hash functions to do the process, so according to your PHP version you have to configure appropriate hashing drivers in your setup; for now we assume that you use version < 7.0 of PHP, otherwise you have to manually enable the mcrypt extension basic on your current version.

install via composer:

$ composer require snappdoctor/drcoder

then use this command if needed:

$ php artisan vendor:publish

The package use env variables that encode/decode process need it to work, so you have to add these variables to your .env file:

ENCODER_SERVICE_IV=SECRET_IV
ENCODER_SERVICE_KEY=SECRET_KEY
ENCODER_SERVICE_MODE=SECRET_MODE
ENCODER_SERVICE_SIGN=SECRET_SIGN
ENCODER_SERVICE_BLOCK_SIZE=BLOCK_SIZE

finall, register your package service provider into config/app.php providers array.

How it works?

first , call the service:

use DrCoder\EncoderService;

for encoding:

$first = "encode_me_1";
$second = "encode_me_2";

$base64_encoded_array = EncoderService::driver(EncoderService::DRIVER_BASE64)
                               ->encode([$first, $second]);
                               
$first_base64_encoded =  $base64_encoded_array[0];
$second_base64_encoded =  $base64_encoded_array[1];

$aes_encoded_array = EncoderService::driver(EncoderService::DRIVER_AES_SSL)
                               ->encode([$first, $second]);
                               
$first_aes_encoded =  $aes_encoded_array[0];
$second_aes_encoded =  $aes_encoded_array[1];

for decoding:

$first = "decode_me_1";
$second = "decode_me_2";

$base64_decoded_array = EncoderService::driver(EncoderService::DRIVER_BASE64)
                               ->decode([$first, $second]);
                               
$first_base64_decoded =  $base64_decoded_array[0];
$second_base64_decoded =  $base64_decoded_array[1];

$aes_decoded_array = EncoderService::driver(EncoderService::DRIVER_BASE64)
                               ->decode([$first, $second]);

$first_aes_decoded =  $aes_decoded_array[0];
$second_aes_decoded =  $aes_decoded_array[1];

you can also use associative arrays and get the response with same index keys. More example file placed in here to get better details of this package.