Code Monkey home page Code Monkey logo

node-laravel-encryptor's People

Contributors

adsegura avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

node-laravel-encryptor's Issues

Exception when trying to use 64 digit key

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.

"EncryptorError: The MAC is invalid." while trying to decrypt right after encryptSync

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.