在浏览器中通过WebCryptoAPI生成ECDH密钥,而不是浏览器化的节点密码模块

我有一个非常小的节点脚本来创build一个公钥/私钥有没有办法在客户端做到这一点,而不必浏览孔encryption模块?

var crypto = require('crypto'); var userCurve = crypto.createECDH('prime256v1'); var userPublicKey = userCurve.generateKeys() var userPrivateKey = userCurve.getPrivateKey(); 

到目前为止,我已经尝试过:

 // https://github.com/diafygi/webcrypto-examples#ecdh---generatekey window.crypto.subtle.generateKey( { name: "ECDH", namedCurve: "P-256", //can be "P-256", "P-384", or "P-521" }, true, //whether the key is extractable (ie can be used in exportKey) ["deriveKey", "deriveBits"] //can be any combination of "deriveKey" and "deriveBits" ) .then(function(key){ //returns a keypair object console.log(key); console.log(key.publicKey); console.log(key.privateKey); }) .catch(function(err){ console.error(err); }); 

但是,当我login它时,它看起来不像节点版本