javascript - 没有 Node.js 我怎么能做 tweetnacl.sealedbox.seal?

标签 javascript node.js

我需要在 javascript 中重新创建这个函数:

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

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

我在 JS 中找到了一个端口,但它需要 Node.js,如果我使用 Node.js,我有兴趣以浏览器的方式进行操作。

有什么事情已经完成了吗?我还没有找到它。

最佳答案

您可以使用 tweetnacl-sealedbox-js 可以在 JSDeliver CDN sealedbox.web.js 上找到的包和 Web 版本.

运行代码片段(基于您的 jsFiddle snippet )以查看它的实际效果:

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/tweetnacl-sealedbox-js@1.2.0/sealedbox.web.js"></script>

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

<h2>Decrypted</h2>
<pre id="decrypted"></pre>

关于javascript - 没有 Node.js 我怎么能做 tweetnacl.sealedbox.seal?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61624467/

相关文章:

node.js - 如何使用 aws ses 在电子邮件 header 中添加姓名

javascript - CSS 的哪个属性不允许固定标题覆盖滚动元素

javascript - Javascript(js)是如何加密和解密的?

javascript - 如何集成 CouchApp、Node.JS、Sammy 和 Mustache

node.js - NodeJS:发现错误:听 EADDRINUSE:::3000?

javascript - 如何在 node.js 中添加换行符?

node.js - 为什么 "$pull"不适用于 findbyidandupdate 请求?

javascript - 用于用户提供坐标的通用 JavaScript 解析器

javascript - 使用javascript获取元素的子元素

javascript - $route.reload 和 ngAnimate