0

I thought this would be a simple matter but it looks like webcrypto api doesn't provide a way to take a private key and generate its public key counterpart.

Is this true? Or am I missing something?

The reason I'm trying to do this is because I want to transfer the keypair and trying to reduce the total size. It would be great if I can just export the private key and later retrieve both of the pairs.

Vlad
  • 8,038
  • 14
  • 60
  • 92
  • Sounds like you're stressing over an insignificant savings of a few hundred bytes at most. – President James K. Polk Jan 24 '18 at 18:44
  • People have reasons for doing things they do. Just because you don't understand why, doesn't mean other they are stupid. In my case I *do* have a need to reduce the size as much as possible. I wish I could go without worrying about this either. – Vlad Jan 24 '18 at 18:46
  • Settle down, I'm required by law to point these things out. – President James K. Polk Jan 24 '18 at 19:21
  • Unfortunately I can't test this but you can try `exportKey()` with `spki` format and then importing that with `importKey()` with `spki` format. Hopefully the `exportKey('spki', )` will only export the public part and not throw a TypeError. – President James K. Polk Jan 24 '18 at 19:25

1 Answers1

0

WebCrypto does not provide a mechanism to derive the public key from a private key.

It is technically possible with the RSA cryptosystem but not necessarily others (see Given a private key, is it possible to derive its public key?) you are only missing e which is generally could be brute forced/guessed (it is usually 65537).

Migrating private keys is something you do not want to do often if at all, every place a software key exists it may leave a remnant (page file, etc) that could be used to discover key later.

If you make the private key exportable (you do not want to do this for security reasons -- see above why) then you could write javascript to do this.

In short, the space savings is probably not worth the complexity and security consequences.

rmhrisk
  • 1,814
  • 10
  • 16