我正在尝试使用 ConcatKDF 算法生成一个通用密钥。在以下示例中,alice 正在尝试使用 bobs 公钥使用 node-jose 库生成一个公共秘密:
const index = require('node-jose/lib/algorithms/index');
const keystore = jose.JWK.createKeyStore();
const bobKey = await keystore.generate('EC', 'P-256');
const aliceKey = await keystore.generate('EC', 'P-256');
const bobPublicKey = bobKey.toJSON();
const alicPrivateKey = aliceKey.toJSON(true);
const props = {
public: bobPublicKey,
length: 256
};
const result = await index.derive('ECDH-CONCAT', alicPrivateKey, props);
它失败并出现以下错误:
Error: invalid EC public key
at validatePublic (node_modules\node-jose\lib\algorithms\ecdh.js:47:29)
at nodejs (node_modules\node-jose\lib\algorithms\ecdh.js:164:13)
at Object.main [as derive] (node_modules\node-jose\lib\algorithms\helpers.js:110:42)
at fn (node_modules\node-jose\lib\algorithms\ecdh.js:207:29)
at Object.exports.derive (node_modules\node-jose\lib\algorithms\index.js:73:10)
at Context.<anonymous> (test\unit\security\ecdh-test.js:108:32)
如果我在这里遗漏了什么,有人可以告诉我吗?
谢谢