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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With