node-laravel-encryptor
NodeJS version of Laravel's Encrypter Class, tested 5.4.30 to 6.0
Illuminate/Encryption/Encrypter.php
With this module you can create the encrypted payload for a cookie from Node Js
and be read by Laravel.
Laravel Encrypter format:
Laravel only allows AES-128-CBC
AES-256-CBC
.
If no algorithm is defined default is AES-256-CBC
{
"iv": "iv in base64",
"value": "encrypted data",
"mac": "Hash HMAC"
}
Install
$> npm i node-laravel-encryptor
Use
const {Encryptor} = require('node-laravel-encryptor');
let encryptor = new Encryptor({
key: 'Laravel APP_KEY without base64:',
});
encryptor
.encrypt({foo: 'bar'})
.then(enc => console.log(enc));
encryptor
.decrypt(enc)
.then(dec => console.log(dec));
Options
Object {key, key_length}
- key: APP_KEY without
base64:
- laravel_key:
DEPRECIATED
- key_length: optional 32|64 for aes-[128]-cbc aes-[256]-cbc
if no key_length
is given default is 64.
Methods
encrypt
arguments:
- data: string
- serialize: optional boolean, if data should be serialized before cipher
if no serialize
option is given default is to serialize.
decrypt
arguments:
- data: string
- serialize: optional boolean, if data should be unserialized after decipher
if no serialize
option is given default is to unserialize.
Tests
$> npm run test
To be able to run PHP test you must have installed:
- PHP >= 7.1.3
- OpenSSL PHP Extension
- Mbstring PHP Extension
- Tokenizer PHP Extension
- Ctype PHP Extension
- JSON PHP Extension
- BCMath PHP Extension
$> npm run test
node Laravel Encrypter
✓ should cipher and decipher
✓ should fail cipher and decipher object without serialize
✓ should cipher and decipher with no key_length defined
✓ should cipher and decipher with no serialize nor unserialize
✓ should fail cipher not valid Laravel Key
✓ should fail cipher not valid algorithm
✓ should fail decipher not valid data
✓ should cipher and decipher multiple times
✓ should decipher data at Laravel correctly (52ms)
✓ should decipher from Laravel correctly (51ms)
10 passing (128ms)