https://github.com/dag0310/otp-crypto
Pseudo one-time pad crypto library for plaintext data exchange.
https://github.com/dag0310/otp-crypto
crypto cryptography encryption key library one-time-pad otp perfect-secrecy random xor
Last synced: 5 months ago
JSON representation
Pseudo one-time pad crypto library for plaintext data exchange.
- Host: GitHub
- URL: https://github.com/dag0310/otp-crypto
- Owner: dag0310
- License: mit
- Created: 2018-02-15T21:10:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-02-16T15:33:37.000Z (over 2 years ago)
- Last Synced: 2025-10-05T13:38:22.273Z (9 months ago)
- Topics: crypto, cryptography, encryption, key, library, one-time-pad, otp, perfect-secrecy, random, xor
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/otp-crypto
- Size: 334 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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`