6.1.1 • Published 3 months ago

otp-crypto v6.1.1

Weekly downloads
6
License
MIT
Repository
github
Last release
3 months ago

OTP Crypto

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

Installation

npm install otp-crypto --save

Demo

Demo - can be found under demo/index.html

API

Please refer to the source of truth: otp-crypto.d.ts

Example

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

6.1.1

3 months ago

5.0.2

6 months ago

5.1.0

6 months ago

5.0.1

6 months ago

5.0.0

6 months ago

6.1.0

6 months ago

6.0.0

6 months ago

4.2.0

6 months ago

4.1.0

6 years ago

4.0.0

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago