有没有办法在 'node-forge' 或其他经过检查和安全的 js oackage 中生成 ecdh 共享密钥

Is there a way for generation of ecdh shared key in 'node-forge' or other checked and secure js oackage

嗯,我想要得到的是这样的东西

import * as forge from 'node-forge'
const aliceKey = forge.pki.ed25519.generateKeyPair();
const bobKey = forge.pki.ed25519.generateKeyPair();

//get shared secret for bob and alice
function getSharedKey(publicKey, privateKey){
//some code
}

const sharedKeyFromAlicePerspective = getSharedKey(bobKey.publicKey , aliceKey.privateKey);
const sharedKeyFromBobPerspective = getSharedKey(aliceKey.publicKey, bobKey.privateKey);

console.log(sharedKeyFromAlicePerspective === sharedKeyFromBobPerspective)//expect 'true'

我也愿意为其他安全和良好维护和测试的库更改库,如果它在这个库提供的标准中是不可能的(我的观点是为各方之间的加密制作尽可能小的安全 public 密钥)

在@Topaco answear 旁边 我发现如果你使用的浏览器支持 Crypto.subtle api 你可以不用模块。

const aliceKey = await window.crypto.subtle.generateKey({name: 'ECDH', namedCurve: 'P-521'},false, ['deriveBits']);
const bobKey = await window.crypto.subtle.generateKey({name: 'ECDH', namedCurve: 'P-521'},false, ['deriveBits']);
const secret = await window.crypto.subtle.deriveBits({
        name: "ECDH",
        namedCurve: "P-521",
        public: bobKey.publicKey
    },
    aliceKey.privateKey, 
    521
)