Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
feistel-cipher
Advanced tools
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.
The main objective of this library is not to provide a secure encryption scheme but rather a safe obfuscation tool.
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:
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 ).
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)
This module is distributed under an MIT license. See the LICENSE file.
FAQs
Feistel cipher implementation for format-preserving encryption
The npm package feistel-cipher receives a total of 74 weekly downloads. As such, feistel-cipher popularity was classified as not popular.
We found that feistel-cipher demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.