如何将Node Crypto.generateKeypairsync转换为DENO?
我想将以下代码从节点(v18.1)程序转换为deno(v1.22),其中在ssh密钥交换过程中生成密钥对:
// generate.mjs
import { generateKeyPairSync } from "crypto";
const keys = generateKeyPairSync("x25519");
上面的代码是较大的SSH客户端的一部分DENO以节点兼容模式运行(- compat
)。但是,GERTATEKEYPAIRSYNC
是尚未实施,所以我想将其更改为deno等效:
deno run --compat --unstable --allow-env ./generate.mjs
error: Uncaught Error: Not implemented: crypto.generateKeyPairSync
throw new Error(message);
^
at notImplemented (https://deno.land/[email protected]/node/_utils.ts:22:9)
at generateKeyPairSync (https://deno.land/[email protected]/node/internal/crypto/keygen.ts:662:3)
at file:///C:/Users/gjzwiers/repos/nodeno_ssh/generate.mjs:3:14
我已经看了 generateKey
在WebCrypto api 中,但似乎它不支持x25519
? WebCrypto API中是否有X25519的替代方法,还是有其他方法可以在DeNo中使用此操作?
I want to convert the following code from a Node (v18.1) program to Deno (v1.22), where a key pair is generated during SSH key exchange:
// generate.mjs
import { generateKeyPairSync } from "crypto";
const keys = generateKeyPairSync("x25519");
The code above is part of a larger SSH client, which mostly works in Deno when run in Node compatibility mode (--compat
). However, generateKeyPairSync
is not yet implemented, so I want to change it to a Deno equivalent:
deno run --compat --unstable --allow-env ./generate.mjs
error: Uncaught Error: Not implemented: crypto.generateKeyPairSync
throw new Error(message);
^
at notImplemented (https://deno.land/[email protected]/node/_utils.ts:22:9)
at generateKeyPairSync (https://deno.land/[email protected]/node/internal/crypto/keygen.ts:662:3)
at file:///C:/Users/gjzwiers/repos/nodeno_ssh/generate.mjs:3:14
I have looked at generateKey
in the WebCrypto API, but it seems that it does not support x25519
? Is there an alternative for x25519 in the WebCrypto API , or is there another way to get this working in Deno?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
新答案:截至Deno 1.33
GenerateKeypairsync
支持如下:旧答案:
我最终使用了评论中建议的外部模块。我使用
node-forge
生成键盘:New answer: As of Deno 1.33
generateKeyPairSync
is supported as follows:Old answer:
I ended up using an external module as suggested in the comments. I used
node-forge
to generate a keypair:也许这可能是可能的解决方案:
请参阅以下答案的原始来源的链接下方的
: https://github.com/tqsw/webcrypto-curve25519/blob/master/master/explainer.md#key-agreement-with-with-x25519
标准(现在我们甚至可以在MDN文档(又名Cli-Browser)中查看他的徽标。
perhaps this can be possible solution:
below the link with original source of this answer:
https://github.com/tQsW/webcrypto-curve25519/blob/master/explainer.md#key-agreement-with-x25519
P.S. Because Deno is very carefully follows Web API standards (now we can even see his logo in browser-compatibility section on MDN documentation, aka cli-browser)... so you can simply use browser's api without any imports of node's modules etc.