Common secret using ConcatKDH in node-jose

96 views Asked by At

I'm trying to generate a common secret key using ConcatKDF algorithm. In the following example alice is trying to generate a common secret using bobs public key using node-jose library:

    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);

It fails with the following error:

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)

Could someone please let me know if I'm missing something here?

Thanks

0

There are 0 answers