Socket
Socket
Sign inDemoInstall

tea-napi

Package Overview
Dependencies
3
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tea-napi

Tiny Encryption Algorithm in N-API


Version published
Weekly downloads
5
Maintainers
1
Created
Weekly downloads
 

Readme

Source

tea-napi

Introduction

Tiny Encryption Algorithm (TEA) for Node.js, in N-API.

Numbers in javascript were signed 32bit integers when doing bit-wise operation.

It's a pain to implement the TEA algorighm in pure javascript, and inefficient too.

So I basically copied the C code from Wikipedia and made it a N-API lib.

It does a IN-PLACE encryption/decryption on the Buffer passed in.

Padding

The last several bytes is left untouched if the Buffer was not aligned to TEA_BLOCK_LEN.

Usage

import { teaEncrypt, teaDecrypt, TEA_BLOCK_LEN, TEA_KEY_LEN } from 'tea-napi';

// Default to 32 cycles.
const ITER = 32;

const data = Buffer.alloc(TEA_BLOCK_LEN + 1);

const key = Buffer.alloc(TEA_KEY_LEN);

const encrypted = teaEncrypt(data, key, ITER);

// Same reference, but actually bytes changed.
assert(encrypted === data);

// The last byte, which is not aligned, was left untouched
assert(encrypted[TEA_BLOCK_LEN + 1] === 0);

const decrypted = teaDecrypt(encrypted, key, ITER);

assert(Buffer.compare(decrypted, Buffer.alloc(TEA_BLOCK_LEN + 1)) === 0);

Keywords

FAQs

Last updated on 11 May 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc