       .then (keys) ->
         deferred1 = Promise.defer()
         keyOpPrivate = window.msCrypto.subtle.exportKey('pkcs8', keys.privateKey)
+        keyOpPrivate.onerror = ->
+          log.error('Failed to export RSA private key using IE web crypto')
         keyOpPrivate.oncomplete = ->
           return deferred1.resolve(Forge.util.createBuffer(keyOpPrivate.result))
         privateKeyPromise = deferred1.promise
 
         deferred2 = Promise.defer()
         keyOpPublic = window.msCrypto.subtle.exportKey('spki', keys.publicKey)
+        keyOpPublic.onerror = ->
+          log.error('Failed to export RSA public key using IE web crypto')
         keyOpPublic.oncomplete = ->
           return deferred2.resolve(Forge.util.createBuffer(keyOpPublic.result))
         publicKeyPromise = deferred2.promise

  'bluebird'
], (require) ->

  Forge        = require 'forge'
  Logger       = require 'kryptnostic.logger'
  Promise      = require 'bluebird'
  
  log          = Logger.get('RsaKeyGenerator')
  
  RSA_KEY_SIZE = 4096
  EXPONENT     = 0x10001

  class RsaKeyGenerator

    
    generate: (params) ->
      if window.crypto?.subtle?
        return @webCryptoGenerate(params)
      else if window.msCrypto?.subtle?
        return @ieWebCryptoGenerate(params)
      else
        return @forgeGenerate(params)

    forgeGenerate: (params) ->
      Promise.resolve()

        window.crypto.subtle.generateKey( {
          name: 'RSA-OAEP'
          modulusLength: params.bits
          publicExponent: params.e
          hash: { name: 'SHA-256' }
        }, true, ['encrypt', 'decrypt'])
      .then (keys) ->
