Here’s a fragment of my script that used to work.
const Protector = {
New: async () => {
let keyPair = await crypto.subtle.generateKey(
{name: 'ECDH', namedCurve: 'P-521'}, true, ['deriveBits']);
return keyPair.publicKey
},
ToString: async (protector) => {
return btoa(String.fromCharCode.apply(null, new Uint8Array(
await crypto.subtle.exportKey('raw', protector))))
},
FromString: async (string) => {
let buffer = new ArrayBuffer(133);
let bytes = new Uint8Array(buffer);
atob(string).split('').forEach(
(char, index) => { bytes[index] = char.charCodeAt(0) });
return await crypto.subtle.importKey('raw', buffer,
{name: 'ECDH', namedCurve: 'P-521'}, false, [])
},
// ...
}
Now if you do await Protector.FromString(await Protector.ToString(await Protector.New))
you’ll get an internal error with crypto.subtle.importKey. This started around 3 weeks ago (on or before 25 June 2022). Is this a bug or have I been doing something wrong?