vibornoff/webcrypto-shim

HMAC fails in IE11

Closed this issue · 1 comments

The following snippet fails in IE11:

var msg = new Uint8Array([ 104, 101, 108, 108, 111 ])
crypto.subtle.generateKey({ name: 'HMAC', hash: { name: 'SHA-256' } }, false, [ 'sign' ])
  .then(function(key) { 
    return crypto.subtle.sign({ name: 'HMAC' }, key, msg) 
  })
  .then(function(digest) {
    document.write('HMAC succeeded, digest: ' + new Uint8Array(digest) + '') 
  })
  .catch(function(err) { 
    console.error(err); 
    document.write('HMAC failed, check console for error details') 
  })

It just returns the generic IE11 { type: "error" } event with no info.

Codepen

This is resolved by supplying the hash parameter again to the sign method as per http://stackoverflow.com/questions/33043091/public-key-encryption-in-microsoft-edge.

This is required in both IE11 and Edge.

crypto.subtle.sign({ name: 'HMAC', hash: { name: 'SHA-256' } }, key, msg) 

Codepen

I'm closing the issue, but I think this is a perfect candidate for inclusion in the shim