           keyPair.publicKey  = publicKey
           return keyPair
         )
-     
-    
 
     # Generate public and private RSA keys
     # returns a Promise object with private and public keys in Forge buffer objects
     generateKeypair: ->
-      params = { bits: RSA_KEY_SIZE, e: EXPONENT }
-      log.info('generating keypair', params)
-      return @generate(params)
-    
-    ##########
-    ## Helpers
-    ##########
-
-    numToUnsignedUint8Array: (num) ->
-      hexString = num.toString(2)
-      binary    = new Uint8Array(hexString.length)
-      for i in [0..hexString.length]
-        binary[i] = hexString[i]
-      uLength     = Math.ceil(binary.length / 8)
-      unsignedInt = new Uint8Array(uLength)
-      for i in [0..uLength]
-        uint8          = binary.subarray(i * 8, i * 8 + 7)
-        # Note: this shit is broken. Should probably hard-code constants.
-        unsignedInt[i] = parseInt(uint8, 2)
-      return unsignedInt
+      if window.crypto?.subtle?
+        params = { bits: RSA_KEY_SIZE, e: EXPONENT_BIG_INT }
+        log.info('generating keypair', params)
+        log.debug('using web crypto API to generate keypair')
+        return @webCryptoGenerate(params)
+      else if window.msCrypto?.subtle?
+        params = { bits: RSA_KEY_SIZE, e: EXPONENT_BIG_INT }
+        log.info('generating keypair', params)
+        log.debug('using IE 11 web crypto API to generate keypair')
+        return @ieWebCryptoGenerate(params)
+      else
+        params = { bits: RSA_KEY_SIZE, e: EXPONENT_NUM }
+        log.info('generating keypair', params)
+        log.debug('using Forge to generate keypair')
+        return @forgeGenerate(params)
 
   return RsaKeyGenerator

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

  'bluebird'
], (require) ->

  Forge            = require 'forge'
  Logger           = require 'kryptnostic.logger'
  Promise          = require 'bluebird'
  
  log              = Logger.get('RsaKeyGenerator')
  
  RSA_KEY_SIZE     = 4096
  EXPONENT_NUM     = 0x10001
  EXPONENT_BIG_INT = new Uint8Array([1, 0, 1])

  class RsaKeyGenerator

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