adsegura / node-laravel-encryptor Goto Github PK
View Code? Open in Web Editor NEWnode version Laravel Encrypter Class
License: MIT License
node version Laravel Encrypter Class
License: MIT License
FIrst off, thank you for making this repo!
node -v
v10.16.0
Using this code:
const { Encryptor } = require("node-laravel-encryptor");
const key = Encryptor.generateRandomKey(64, "base64");
let encryptor = new Encryptor({
key: key,
key_length: 64
});
const result = encryptor.encryptSync("TEXTTOENCRYPT");
console.log(result);
Exception is thrown:
EncryptorError: Invalid key length
at Function.throwError (node_modules/node-laravel-encryptor/dist/base_encryptor.js:256:15)
at Encryptor.createCipher (node_modules/node-laravel-encryptor/dist/base_encryptor.js:144:28)
at Encryptor.encryptItSync (node_modules/node-laravel-encryptor/dist/base_encryptor.js:35:29)
at Encryptor.encryptSync (node_modules/node-laravel-encryptor/dist/Encryptor.js:21:50)
Yet, if I make a key of 32 and don't pass a key_length into the Encryptor constructor, it works. It's like the cipher algorithm isn't being set properly when the key is 64 digits.
Here's the sample code from my project to test the decryption:
var encr = new Encryptor({
key: this.AppConfig.client.secret_key
});
// eAXA9htTlhMlqcQrKtwSkDNfRn9G1/PleiDvyxANaUQ=
console.log(this.AppConfig.client.secret_key);
var enc = encr.encryptSync('test');
// eyJpdiI6IlltRXhOVFk1TXpGaE5UWTBOVGc1TXc9PSIsInZhbHVlIjoiVll3MHFOVXB5b0xBREoxMXcvcmlodz09IiwibWFjIjoiYjRhNzZkMmU5YzM4ZDZlNjcxM2Q1YzNjODI4MTI5ZTYyZDQ5YTBjMzI5YWUwNTRjN2E1MmUzNWIwOGIyMGY2MSJ9
console.log(enc);
console.log(encr.decrypt(enc));
The encrypted result is valid when decrypted in Laravel, but always return invalid MAC when I'm trying to decrypt it in JS.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.