This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28578 - No "raw" export/import for ECDSA
Summary: No "raw" export/import for ECDSA
Status: RESOLVED DUPLICATE of bug 27447
Alias: None
Product: Web Cryptography
Classification: Unclassified
Component: Web Cryptography API Document (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Ryan Sleevi
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-28 17:01 UTC by Martin Thomson
Modified: 2015-04-28 17:04 UTC (History)
1 user (show)

See Also:


Attachments

Description Martin Thomson 2015-04-28 17:01:22 UTC
This is trivial to shim, but inexplicably absent from the spec.

  const SPKI_PREFIX = { 
    "P-256": new Uint8Array([
      48, 86, 48, 16, 6, 4, 43, 129, 4, 112, 6, 8,
      42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0])
// add more
  };

  function importRawPublicKey(pub, alg, usages) {
    var prefix = SPKI_PREFIX[alg.namedCurve];
    var spki = new Uint8Array(prefix.byteLength + pub.byteLength);
    spki.set(prefix, 0);
    spki.set(pub, prefix.byteLength);
    return crypto.subtle.importKey('spki', spki, alg, true, usages);
  };

  function exportRawPublicKey(key, alg) {
    return crypto.subtle.exportKey('spki', key)
             .then(spki => new Uint8Array(spki, SPKI_PREFIX[alg.namedCurve]));
  };
Comment 1 Martin Thomson 2015-04-28 17:04:58 UTC
I missed this first time around.

*** This bug has been marked as a duplicate of bug 27447 ***