You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionfromHex(value: string): Uint8Array{if(value.length%2!==0){thrownewError(`Input cannot contain a hex value, 'value' length must be even`,);}consttester=/^(?:[a-f0-9]{2})*$/i;if(!tester.test(value)){thrownewError(`Input does not contain a valid hex value`);}constout=newUint8Array(value.length/2);for(leti=0;i<value.length;i+=2){constval=value.substring(i,i+2);out[i/2]=parseInt(val,16);}returnout;}constalgorithm={name: "ECDH",namedCurve: "P-256",}constkeyHEX=prompt('Type the key and press [Enter]:')constkeySPKI=fromHex(keyHEX);constpublicKey=awaitcrypto.subtle.importKey('spki',keySPKI,algorithm,false,[]);
I've performed the following tests:
Export a key on deno and import it on deno
Export a key on deno and import it on chrome
Export a key on chrome and import it on deno
Export a key on chrome and import it on chrome
The import of the key generated by deno both on deno itself and on chrome threw an exception:
On deno a DOMException: unknown algorithm
On chrome a generic Uncaught Error
The import of the key generated by chrome both on deno and on chrome itself did work without any problem.
The version of deno used for these tests is 1.24.3
The version of chrome used for these tests is 104
The OS used during the tests is: Windows 10.0.19044.1889
Here follows some example of public keys generated both by deno and by chrome: Deno:
The text was updated successfully, but these errors were encountered:
Menecats
changed the title
ECDH P-256: Fail to import public keys
ECDH P-256: Exporting public key to 'spki' format produces an invalid result
Aug 21, 2022
The result is valid but unfortunately not interoperable (even with Deno itself upon import it seems). Since that particular comment Node.js has further removed some of the non-interoperable key algorithm's support.
Exporting a ECDH P-256 key in the
spki
format produced a non-valid key.The following two scripts allow to export and import a
spki
key:Export:
Import:
I've performed the following tests:
The import of the key generated by deno both on deno itself and on chrome threw an exception:
DOMException: unknown algorithm
Uncaught Error
The import of the key generated by chrome both on deno and on chrome itself did work without any problem.
The version of deno used for these tests is
1.24.3
The version of chrome used for these tests is
104
The OS used during the tests is:
Windows 10.0.19044.1889
Here follows some example of public keys generated both by deno and by chrome:
Deno:
Chrome:
The text was updated successfully, but these errors were encountered: