# tea-napi

> Tiny Encryption Algorithm in N-API

Latest version **0.0.5** (published 2021-05-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install tea-napi
pnpm add tea-napi
yarn add tea-napi
bun add tea-napi
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2021-05-11 |
| First published | 2021-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | yanlong.wang@naiver.org |
| Maintainers | nomagick |
| Keywords | tea, napi, cryptology, crypto, encrypt, decrypt |

## Links

- npm: https://www.npmjs.com/package/tea-napi
- Homepage: https://github.com/nomagick/tea-napi
- npm.io page: https://npm.io/package/tea-napi

## Dependencies (2)

- [bindings](https://npm.io/package/bindings.md) *
- [node-addon-api](https://npm.io/package/node-addon-api.md) *

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2021-05-11
- 0.0.4 — 2021-05-06
- 0.0.3 — 2021-05-06
- 0.0.2 — 2021-05-06
- 0.0.1 — 2021-04-30

## README

# 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

```typescript
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);

```

---
_Source: https://npm.io/package/tea-napi · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
