GithubHelp home page GithubHelp logo

ecollect / node-fe1-fpe Goto Github PK

View Code? Open in Web Editor NEW
17.0 7.0 1.0 57 KB

Node.js implementation of the FE1 Format Preserving Encryption algorithm.

License: MIT License

JavaScript 100.00%
node-js encryption javascript server backend node-fe1-fpe format-preserving-encryption

node-fe1-fpe's People

Contributors

nanov avatar sp1tz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

vladhristov

node-fe1-fpe's Issues

Decryption wrong if format() is less than firstFactor

The calculation of left in decryption can result in a negative number when modulu is less than 0,

left = (modulu > 0) ? firstFactor - modulu : modulu;

this leads to a failure to recover the original value.

The value produced should be based on - modulu in all cases (to ensure a positive result):

 left = (modulu > 0) ? firstFactor - modulu : - modulu; 

You can confirm this change is an improvement by

  • first removing all expectedEV assertions from the unit tests (tests should still pass with less assertions)
  • modifying the format() function to return ... % 100n to force the modulu <= 0 case to occur, (tests now fail).
  • then updating the code as above. (tests pass again, because the code was fixed).

Then remember to

  • restore the current format() function.
  • restore the current test code (all original tests will still pass with all assertions).

README shows different results from actual

Should I expect to get the same encrypted result as what is shown in the README?
I get 5011 instead of 4984:

$ node
Welcome to Node.js v12.14.1.
> const fe1 = require('node-fe1-fpe');
> const v = fe1.encrypt(10001, 1, 'my-secret-key', 'my-non-secret-tweak');
> console.log(v)
5011
> const d = fe1.decrypt(10001, v, 'my-secret-key', 'my-non-secret-tweak');
> console.log(d);
1

// curious what 4984 decrypts to:
> const d2 = fe1.decrypt(10001, 4984, 'my-secret-key', 'my-non-secret-tweak');
> console.log(d2);
6786

Credit card example?

Hi, it looks like currently modulo is supported up to 10 000 000. But for 15-digit credit card, don't we need 10^15 modulo?

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.