# otp-crypto

> Pseudo one-time pad crypto library for plaintext data exchange.

Latest version **6.1.1** (published 2024-02-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install otp-crypto
pnpm add otp-crypto
yarn add otp-crypto
bun add otp-crypto
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.1.1 |
| Published | 2024-02-16 |
| First published | 2018-02-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20.0.0 |
| Dependencies | 0 |
| Unpacked size | 18.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Daniel Geymayer |
| Maintainers | dag0310 |
| Keywords | otp, one-time-pad, encryption, perfect-secrecy, random, bytes, vernam, xor, cryptography, crypto, library, lib |

## Links

- npm: https://www.npmjs.com/package/otp-crypto
- Repository: https://github.com/dag0310/otp-crypto
- Homepage: https://github.com/dag0310/otp-crypto#readme
- Issues: https://github.com/dag0310/otp-crypto/issues
- npm.io page: https://npm.io/package/otp-crypto

## 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

- 6.1.1 (latest) — 2024-02-16
- 6.1.0 — 2023-11-25
- 4.2.0 — 2023-11-25
- 6.0.0 — 2023-11-13
- 5.1.0 — 2023-11-13
- 5.0.2 — 2023-11-13
- 5.0.1 — 2023-11-09
- 5.0.0 — 2023-11-06
- 4.1.0 — 2018-02-23
- 4.0.0 — 2018-02-22
- 3.0.0 — 2018-02-16
- 1.0.0 — 2018-02-15

## README

# OTP Crypto

Pseudo one-time pad crypto library for plaintext data exchange.

## Installation

`npm install otp-crypto --save`

## Demo

[Demo](https://dag0310.github.io/otp-crypto/demo/) - can be found under `demo/index.html`

## API

Please refer to the source of truth: [otp-crypto.d.ts](src/otp-crypto.d.ts)

## Example

```javascript
// Generate a random byte array key with a predefined length:
let keySender = OtpCrypto.generateRandomBytes(1000)
let keyReceiver = keySender.slice(0) // copy of key, which in real-life needs to be exchanged somehow

// Encrypt a message to Base64 with the sender's key:
const secretMessageUnencrypted = 'TOP SECRET MESSAGE.'
const otpEncrypted = OtpCrypto.encrypt(secretMessageUnencrypted, keySender)
keySender = otpEncrypted.remainingKey

// Decrypt the message to plaintext with the receiver's key:
const otpDecrypted = OtpCrypto.decrypt(otpEncrypted.base64Encrypted, keyReceiver)
keyReceiver = otpDecrypted.remainingKey

// Extract the decrypted message
const secretMessageDecrypted = otpDecrypted.plaintextDecrypted // 'TOP SECRET MESSAGE.'

// Now both sender and receiver have the same key again (shorter than before).
// They can continue sending more messages with the remaining key.
```

## Dev corner

Run linter: `npm run lint`

Run tests: `npm run test`

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