Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do tweetnacl.sealedbox.seal without Node.js?

I need to recreate this function in javascript:

tweetnacl.sealedbox.seal(new Uint8Array(n[0]), w); // w is a parseKey

https://github.com/dchest/tweetnacl-js

I have found a port in JS but it requires Node.js and I am interested in doing it in a browser way if I use Node.

Is there something already done? I haven't found it.

like image 335
ephramd Avatar asked Oct 16 '22 03:10

ephramd


1 Answers

You can use tweetnacl-sealedbox-js package and the web version that you can find on JSDeliver CDN sealedbox.web.js.

Run the code snippet (which is based on your jsFiddle snippet) to see it in action:

const buffer = new Uint8Array([1,2,3,4,5]);
const keyPair = nacl.box.keyPair();
const sealed = sealedBox.seal(buffer, keyPair.publicKey);
const result = sealedBox.open(sealed, keyPair.publicKey, keyPair.secretKey);

document.getElementById('sealed').textContent = sealed;
document.getElementById('decrypted').textContent = result;
<script src="https://tweetnacl.js.org/nacl.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/sealedbox.web.js"></script>

<h2>Sealed</h2>
<pre id="sealed"></pre>

<h2>Decrypted</h2>
<pre id="decrypted"></pre>
like image 134
Christos Lytras Avatar answered Oct 19 '22 01:10

Christos Lytras