node version Laravel Illuminate/Encryption/Encrypter.php
npm install node-laravel-encryptor

NodeJS version of Laravel's Encrypter Class, tested 5.4.30 to 6.X
Illuminate/Encryption/Encrypter.php
With this module you can create the encrypted payload for a cookie from Node Js
and be read by Laravel.
You can use it too as standalone module to encrypt and decrypt data with verified signature.
If you use this module as standalone, AKA without Laravel
backend involve in your scenarios you can use native node JSON lib to serialize
the data before ciphering it.
options.key_length now is 128|256.>=v8.10.0 (npm v5.6.0)>=5.4.30sh
$> npm i node-laravel-encryptor
`Use
$3
`js
const {Encryptor} = require('node-laravel-encryptor');let encryptor = new Encryptor({
key: 'Laravel APP_KEY without base64:',
});
encryptor
.encrypt({foo: 'bar'})
.then(enc => console.log(encryptor.decrypt(enc)));
`$3
`js
const enc = encryptor.encryptSync({foo: 'bar'});console.log(encryptor.decrypt(enc));
`Decrypt is always in sync mode.
Serialize
||Encryptor let you chose between
php-serialize npm package or JSON node native implementation to serialize the data out of the box.If you need to use other serialize library, like
mspack or any other custom lib, Encryptor let you inject, at the constructor or at runtime with
setSerializerDriver(your_lib), your custom Serializer Class. > If you use this module with the intend to be able to read and write ciphered data to/from Laravel you should instance Encryptor class without any
serialize_mode option, just the defaults.> If you use this module without any Laravel Backend involve you should use json mode, instance Encryptor class with
serialize_mode:'json'.Encryptor will serialize only if data to cipher is an object.
You can force serialize if Encryptor class is using
serialize_mode:'php' to be able to serialize data to send back to Laravel if needed##### Use php-serialize to serialize data (Laravel integration)
`js
const encryptor = new Encryptor({key});
const encryptor1 = new Encryptor({key, serialize_mode: 'php'});
`
encryptor and encryptor1 just do the same, initialize Encryptor class with serialize mode to 'php'> Encryptor defaults serialize data with
php-serialize driver to be compliant with Laravel ##### Force serialize only when
serialize_mode:'php'
If data needs to be serialized but it's not an object (because Laravel is serializing everything)
you can force Encryptor.encrypt() to serialize data.
`js
const encryptor = new Encryptor({key}); //serialize_mode = 'php'
encryptor.encrypt('foo', true) //foo now is encrypted and serialized
` ##### Use JSON to serialize data
`js
const encryptor = new Encryptor({key, serialize_mode: 'json'});
`#### Write your custom Serializer
#### Prerequisites
* adhere to Serializer Interface contract
Your custom Serializer must implement this two methods:
`ts
export interface Serialize_Interface {
serialize(data: any): string;
unSerialize(data: string): any;
}
` Encryptor Class
#### Constructor
* arguments:
* options: