https://github.com/github/tweetsodium
libsodium sealed cryptobox using tweetnacl
https://github.com/github/tweetsodium
Last synced: 5 months ago
JSON representation
libsodium sealed cryptobox using tweetnacl
- Host: GitHub
- URL: https://github.com/github/tweetsodium
- Owner: github
- License: mit
- Archived: true
- Created: 2018-09-17T16:39:05.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2022-04-05T23:10:28.000Z (almost 4 years ago)
- Last Synced: 2025-09-04T17:58:05.469Z (6 months ago)
- Language: JavaScript
- Size: 112 KB
- Stars: 44
- Watchers: 4
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ⚠️ `tweetsodium` is deprecated and unmaintained ⚠️
Consider using [`libsodium.js`](https://github.com/jedisct1/libsodium.js), maintained by the same author as `libsodium`. For example:
```js
import libsodium from "libsodium-wrappers";
// Compatible with the same `Uint8Array` arguments as `tweetsodium.seal()`
async function async_encrypt(messageBytes, publicKey) {
await libsodium.ready;
return libsodium.crypto_box_seal(messageBytes, publicKey);
}
// Compatible with the same `Uint8Array` arguments as `tweetsodium.sealOpen()`
async function async_decrypt(messageBytes, publicKey, privateKey) {
await libsodium.ready;
return libsodium.crypto_box_seal_open(messageBytes, publicKey, privateKey);
}
```
Or if you are able to use top-level await:
```js
import libsodium from "libsodium-wrappers";
await libsodium.ready;
// Use:
// - `libsodium.crypto_box_seal` instead of `tweetsodium.seal`
// - `libsodium.crypto_box_seal_open` instead of `tweetsodium.sealOpen`
```
---
# tweetsodium [](https://travis-ci.org/mastahyeti/tweetsodium)
This library implements [libsodium's sealed boxes](https://download.libsodium.org/doc/public-key_cryptography/sealed_boxes) using the [tweetnacl-js](https://github.com/dchest/tweetnacl-js) and [blakejs](https://github.com/dcposch/blakejs) libraries.
## Usage
```javascript
const nacl = require("tweetnacl");
const sodium = require("tweetsodium");
// generate public key to use for encryption and coresponding secret key to use
// for decryption
const keyPair = nacl.box.keyPair();
// encrypts message string using public key
function encrypt(message) {
const encoder = new TextEncoder();
const messageBytes = encoder.encode(message);
return sodium.seal(messageBytes, keyPair.publicKey);
}
// decrypts message using secret key
function decrypt(ciphertext) {
const encoder = new TextEncoder();
const ciphertextBytes = encoder.encode(ciphertext);
return sodium.sealOpen(ciphertextBytes, keyPair.publicKey, keyPair.secretKey);
}
```