Derive key with PBKDF2 for HMAC?
Opened this issue · 2 comments
claq2 commented
Do browsers really support generating HMAC keys with PBKDF2? Both Chrome and Firefox seem to complain when I pass {name:"HMAC"} to deriveKey in the 3rd parameter. I can't seem to find a definitive answer anywhere.
JustinDrake commented
Same here. The error I get on Chrome is
HmacImportParams: hash: Missing or not an AlgorithmIdentifier
On Safari:
NotSupportedError (DOM Exception 9): The operation is not supported.
On Firefox the promise hangs.
ehuggett commented
This works for me*, does it help? (or have i misunderstood the issue)
const pwdKey = await window.crypto.subtle.importKey(
'raw',
encoder.encode(password),
{ name: 'PBKDF2' },
false,
['deriveKey']
);
const newAuthKey = await window.crypto.subtle.deriveKey(
{
name: 'PBKDF2',
salt: encoder.encode(file.url),
iterations: 100,
hash: 'SHA-256'
},
pwdKey,
{
name: 'HMAC',
hash: 'SHA-256'
},
true,
['sign']
);
*Firefox ESR 52.4.0 and Firefox Developer Edition 57.0b10