npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ubiq-security-fpe

v2.0.0

Published

Ubiq Security, Inc. Format Preserving Encryption functions

Downloads

233

Readme

Format Preserving Encryption in Node

An implementation of the NIST-approved FF1 and FF3-1 algorithms in Node.

This implementation conforms (as best as possible) to Draft SP 800-38G Rev. 1. The implementation passes all tests specified by NIST in their Cryptographic Standards and Guidelines examples for FF1; however, no official examples/samples exist (or are known) for FF3-1. FF3 is not implemented as NIST has officially deprecated its use in light of recent cryptanalysis performed on it.

Installation

Using the npm or yarn package managers:

You may want to make sure you are running the latest version of npm or yarn by first executing

$ npm install -g npm
# or
$ npm install -g yarn

Install the ubiq-security-fpe package with:

$ npm install ubiq-security-fpe
# or
$ yarn add ubiq-security-fpe

To build and install directly from a clone of the gitlab repository source:

$ git clone [email protected]:ubiqsecurity/ubiq-fpe-node.git
$ cd ubiq-node-fpe
$ npm install

Requirements

Node.js version 12 or later npm version 6 or later

All dependencies are pre-required in the module itself.

Testing

To run the tests:

$ npm run test

As described above, the unit tests for FF1 come from the NIST guidelines. As no such guidelines are available for FF3-1, the unit tests verify only that the encryption and decryption implementations are compatible with each other.

Documentation

See the Node API docs.

About alphabets and the radix parameter

The interfaces operate on strings, and the radix parameter determines which characters are valid within those strings, i.e. the alphabet. For example, if your radix is 10, then the alphabet for your plain text consists of the characters in the string "0123456789". If your radix is 16, then the alphabet is the characters in the string "0123456789abcdef".

A radix of up to 255 is supported, and the alphabet for a radix of 36 is "0123456789abcdefghijklmnopqrstuvwxyz".

Tweaks

Tweaks are very much like Initialization Vectors (IVs) in "traditional" encryption algorithms. For FF1, the minimun and maximum allowed lengths of the tweak may be specified by the user, and any tweak length between those values may be used. For FF3-1, the size of the tweak is fixed at 7 bytes.

Plain/ciphertext input lengths

For both FF1 and FF3-1, the minimum length is determined by the inequality:

  • radixminlen >= 1000000

or:

  • minlen >= 6 / log10 radix

Thus, the minimum length is determined by the radix and is automatically calculated from it.

For FF1, the maximum input length is

  • 232

For FF3-1, the maximum input length is

  • 2 * logradix 296

or:

  • 192 / log2 radix

Examples

The unit test code provides the best and simplest example of how to use the interfaces.

FF1

   /*
     * @key is an array of bytes which must be 16, 24, or 32 long
     * @twk is an array of bytes of which must be between @twkmin
     *     and @twkmax lengths passed in. 
     * @custom_radix_str is the custom radix string indicating valid
     *     characters allowed by @PT and @encrypted_text.  In this
     *     case, Radix 10 (numeric) is being used.
     * 
     * @PT is "user input" for the data being encrypted
     */

    const custom_radix_str = "0123456789"

    const ctx = new FF1(key, twk, twkmin, twkmax, custom_radix_str.length, custom_radix_str);
    const cipher_text = ctx.encrypt(PT);
    const decrypted_text = ctx.decrypt(cipher_text);