Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Support create public key from components method? #24471

Closed
belldoor opened this issue Nov 19, 2018 · 10 comments
Closed

Feature request: Support create public key from components method? #24471

belldoor opened this issue Nov 19, 2018 · 10 comments
Labels
crypto Issues and PRs related to the crypto subsystem. feature request Issues that request new features to be added to Node.js. stale

Comments

@belldoor
Copy link

belldoor commented Nov 19, 2018

I cannot use ursa anymore at node v10. So I'm trying to move to native crypto.
But the problem is, native crypto seems not support create public key from components.

So, why don't you support create public key from components method?


const ursa = require('ursa');

// modulus should be a base64/base64Url string
const modulus = new Buffer(modulusStr, 'base64');
// exponent should be base64/base64url
const exponent = new Buffer('AQAB', 'base64');

const pubKey = ursa.createPublicKeyFromComponents(modulus, exponent);
console.info(pubKey.toPublicPem('utf8')); 
// ------BEGIN PUBLIC KEY------
// ...
const nodeRSA = require('node-rsa');
const key = new nodeRSA();

const modulus = new Buffer(modulusStr, 'base64');
const exponent = new Buffer('AQAB', 'base64');

const pubKey = key.importKey({ n: modulus, e: exponent }, 'components-public');
console.info(pubKey.exportKey('pkcs8-public-pem'));
// ------BEGIN PUBLIC KEY------
// ...
@Trott
Copy link
Member

Trott commented Nov 19, 2018

@nodejs/crypto

@Trott Trott added crypto Issues and PRs related to the crypto subsystem. question Issues that look for answers. feature request Issues that request new features to be added to Node.js. labels Nov 19, 2018
@tniessen
Copy link
Member

This came up in a discussion around the key object API recently. Currently, the only way to do this is to manually create an SPKI structure. That might change in the future, though.

@bnoordhuis
Copy link
Member

@tniessen Can you clarify? I assume you're not talking about openssl's NETSCAPE_SPKI.

There's DSA_set0_key() and RSA_set0_key(). I'd be okay with adding bindings for those. We already use/expose DH_set0_key().

It might get a bit awkward if we also want to support EC keys through the same API because they're quite different from RSA and DSA keys, and because there's some overlap with the ECDH class.

(ECDH can generate keys from an arbitrary private key. 'Arbitrary' in the sense that the private key is just a bignum encoded as a buffer.)


On the other hand, DSA and RSA keys have well-defined formats. It's not hard to write a npm module that takes some BigInts and spits out PEM. There's no real reason it should live in core except convenience.

@tniessen
Copy link
Member

Sorry, Ben, I must have missed the notitfication.

Can you clarify? I assume you're not talking about openssl's NETSCAPE_SPKI.

I meant this, where PEM would encode a SubjectPublicKeyInfo (SPKI) structure:

On the other hand, DSA and RSA keys have well-defined formats. It's not hard to write a npm module that takes some BigInts and spits out PEM. There's no real reason it should live in core except convenience.


I think this discussion should be aligned with the more recent comments in #15113 regarding JWK support. JWK recommends support for EC, by the way.

@jainendra
Copy link

@belldoor Is there anyway to do this now ?

@bnoordhuis
Copy link
Member

@jainendra You can use https://www.npmjs.com/package/bursar (I wrote it a while ago in response to this issue but I forgot to publish it... Done just now.)

Some examples here: https://github.com/bnoordhuis/node-bursar/blob/9447b188b9f424a72dac5a318a1ffe6596057822/test.js#L30-L85

@tniessen
Copy link
Member

tniessen commented Jan 4, 2020

I am considering extending #30045 with a .fields property to retrieve components, and adding a KeyObject.from({ type, asymmetricKeyType, params: { ... }, fields: { ... } }) function, but I am open to other ideas, too. (cc @panva)

@panva
Copy link
Member

panva commented Jan 4, 2020

@tniessen sounds great!

@github-actions
Copy link
Contributor

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label May 15, 2022
@github-actions
Copy link
Contributor

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem. feature request Issues that request new features to be added to Node.js. stale
Projects
None yet
Development

No branches or pull requests

7 participants