我需要在 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/