Reputation: 287745
I have the following code:
crypto.subtle.generateKey({
name: 'ECDSA',
namedCurve: 'P-256',
}, true, ['sign', 'verify']).then(function(key) {
console.log('generated key');
}).catch(function(err) {
console.log('error: ' + err + ', as JSON: ' + JSON.stringify(err));
});
When I run this code (live demo here) in Chrome or Firefox, it prints out generated key
. In Microsoft Edge 14.14393, however, the output is very strange:
error: [object Object], as JSON: {"name":"ECDSA","namedCurve":"P-256"}
Why is Edge throwing an error here?
Why is the error thrown not a normal error object, but the algorithm specification?
How do I generate an ECDSA key in Edge?
Upvotes: 1
Views: 197
Reputation: 35796
According to the Web Cryptography API documentation for Edge, it doesn't look like the ECDSA algorithm is supported as of now.
I don't really get why the error matches the payload you passed to the generateKey
method, but it looks like a bug to me.
Regarding what you can do, you could use a library like elliptic that will allow you to generate your key client-side. It has been tested under Edge 13 and assuming the error you're experiencing is not due to 14, it seems that it could be a good solution.
const EC = require('elliptic').ec
const ec = new EC('p256')
const key = ec.genKeyPair()
I guess you also don't want to rely on an api call that would be responsible of generating and sending back the key since it might compromise your system, but that could also be one way to get around the problem.
Upvotes: 3