Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

feistel-cipher

Package Overview
Dependencies
Maintainers
5
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feistel-cipher

Feistel cipher implementation for (almost) format-preserving encryption

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
88
increased by104.65%
Maintainers
5
Weekly downloads
 
Created
Source

feistel-cipher

GitHub tag (latest by date) npm GitHub last commit GitHub issues NPM

This is a TypeScript library implementing the Feistel cipher for "almost" format-preserving encryption. "Almost" because as we use a balanced version of the implementation, we need the input string to be of even length. If that's the case, the length will be preserved, otherwise the output will be one character longer.

Motivation

The main objective of this library is not to provide a secure encryption scheme but rather a safe obfuscation tool.

Formal description

This library operates on the concept of the Feistel cipher described in Wikipedia as:

A Feistel network is subdivided into several rounds or steps. In its balanced version, the network processes the data in two parts of identical size. On each round, the two blocks are exchanged, then one of the blocks is combined with a transformed version of the other block. Half of the data is encoded with the key, then the result of this operation is added using an XOR operation to the other half of the data. Then in the next round, we reverse: it is the turn of the last half to be encrypted and then to be xored to the first half, except that we use the data previously encrypted. The diagram below shows the data flow (the represents the XOR operation). Each round uses an intermediate key, usually taken from the main key via a generation called key schedule. The operations performed during encryption with these intermediate keys are specific to each algorithm.

The algorithmic description (provided by Wikipedia) of the encryption is as follows:

  • Let be the number of steps, the keys associated with each step and a function of the space to the word space.
  • For each step , note the encrypted word in step :
  • is the unciphered text, is the ciphered word.

There is no restriction on the function other than the XOR operation must be possible. For simplicity, we will choose of the same size as and the function shall transform a word of length into a word of length (and this for all ).

Usage

npm i feistel-cipher

To get an obfuscated string from a source data, first instantiate a Cipher object, passing it a key and a number of rounds. Then, use the encrypt() method with the source data as argument. The result will be a Buffer. To ensure maximum security, we recommend you use a 256-bit key or longer and a minimum of 10 rounds.

The decryption process uses the obfuscated buffered data and pass it to the decrypt() method of the Cipher.

import * as feistel from 'feistel-cipher'

const source = 'my-source-data'

// Encrypt
const cipher = new feistel.Cipher('some-32-byte-long-key-to-be-safe', 10)
const obfuscated = cipher.encrypt(source)

// Decrypt
const deciphered = cipher.decrypt(obfuscated)

assert(deciphered == source)

License

This module is distributed under an MIT license. See the LICENSE file.


© 2020 Edgewhere SAS. All rights reserved.

Keywords

FAQs

Package last updated on 08 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc