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

mtcv3-encryption

v1.0.1

Published

A brief description of the mtcv3 package.

Downloads

128

Readme

MTCv3 Encryption Library

MIT License Node.js

MTCv3 is a custom cryptographic encryption library inspired by the Advanced Encryption Standard (AES). It offers flexibility with customizable parameters, making it suitable for various encryption needs. The library is designed to provide block-based encryption with built-in modes like CBC, using AES-inspired transformations and customizable key schedules.


Table of Contents


Features

  • Block Cipher: Implements a block cipher mode, similar to AES's CBC (Cipher Block Chaining).
  • Configurable Parameters: Allows customization of rounds, matrix size, and key derivation parameters.
  • AES-Inspired Operations: Uses AES S-Box substitutions, MixColumns-like mixing layer, and bit-level permutations.
  • Key Derivation: Utilizes PBKDF2 with SHA-256 to derive keys from a password and salt.
  • CBC Mode Encryption: Ensures data confidentiality across multiple blocks by using Cipher Block Chaining (CBC) mode.

Installation

To install MTCv3 in your Node.js project, run:

yarn add mtcv3-encryption
# or
npm install mtcv3-encryption

Usage

Basic Example

Here’s a quick example of using MTCv3 to encrypt and decrypt data:

import { MTCv3 } from 'mtcv3-encryption';

// Initialize with a password and salt
const password = 'strongpassword';
const salt = 'somesalt';
const mtc = new MTCv3(password, salt);

// Encrypt a message
const plaintext = 'HELLO WORLD';
const ciphertext = mtc.encrypt(plaintext);
console.log('Ciphertext:', ciphertext);

// Decrypt the message
const decryptedText = mtc.decrypt(ciphertext);
console.log('Decrypted Text:', decryptedText); // Output should be 'HELLO WORLD'

Custom Parameters

The library allows customization for encryption rounds and matrix size. Adjust these parameters based on your security and performance requirements.

const rounds = 12;
const matrixSize = 4; // Default size for AES-like encryption

const mtcCustom = new MTCv3(password, salt, rounds, matrixSize);

const customCiphertext = mtcCustom.encrypt(plaintext);
const customDecryptedText = mtcCustom.decrypt(customCiphertext);
console.log('Custom Decrypted Text:', customDecryptedText);

API Documentation

Constructor

new MTCv3(password: string, salt: string, rounds?: number, matrixSize?: number)
  • password: A string password used for key derivation.
  • salt: A string salt for key derivation.
  • rounds (optional): Number of encryption rounds. Default is 10.
  • matrixSize (optional): Size of the internal matrix. Default is 4.

Methods

  • encrypt(plaintext: string): string: Encrypts the provided plaintext string and returns the ciphertext in hexadecimal format.

  • decrypt(ciphertextHex: string): string: Decrypts the provided ciphertext (in hexadecimal format) and returns the plaintext string.


Security Considerations

Warning: MTCv3 is a custom encryption algorithm and has not been formally peer-reviewed. While it incorporates AES-inspired components, it has not undergone extensive cryptanalysis. For critical or production-level applications, consider using standardized encryption methods like AES or ChaCha20.

Padding Oracle Attack: MTCv3 uses PKCS#7 padding in CBC mode. To prevent padding oracle attacks, ensure that padding errors do not leak information to the attacker.


Performance

MTCv3 is optimized for flexibility rather than speed. It performs well in software-only environments but does not currently support hardware acceleration. For high-performance needs, AES with hardware acceleration or ChaCha20 may be more suitable.


Testing

Unit Tests

This project includes a suite of unit tests that verify encryption and decryption functionality, error handling, and consistency. To run the tests, you can use Jest or another testing framework:

yarn test
# or
npm test

Sample Tests

describe('MTCv3 Encryption', () => {
  it('should correctly encrypt and decrypt text', () => {
    const password = 'password';
    const salt = 'salt';
    const mtc = new MTCv3(password, salt);

    const plaintext = 'HELLO WORLD';
    const ciphertext = mtc.encrypt(plaintext);
    const decrypted = mtc.decrypt(ciphertext);

    expect(decrypted).toBe(plaintext);
  });
});

For more details on test coverage, refer to the tests directory.


License

MTCv3 is licensed under the MIT License. See LICENSE for more information.


This project is a work in progress, and contributions, suggestions, or discussions around improving security or performance are welcome.