   'use strict'
 
   # libraries
-  Forge = require 'forge'
+  forge = require 'forge'
 
   # kryptnostic
   AbstractCryptoService = require 'kryptnostic.abstract-crypto-service'


      if not @key
        logger.info('no key passed! generating a key.')
        @key = Forge.random.getBytesSync(@cypher.keySize / BITS_PER_BYTE)
      @abstractCryptoService = new AbstractCryptoService(@cypher)

    encrypt: (plaintext) ->

      iv         = Forge.random.getBytesSync(AesCryptoService.BLOCK_CIPHER_KEY_SIZE)
      ciphertext = @abstractCryptoService.encrypt(@key, iv, plaintext)

      return new BlockCiphertext {
        iv       : btoa(iv)
        salt     : btoa(Forge.random.getBytesSync(0))
        contents : btoa(ciphertext)
      }

    encryptUint8Array: (uint8) ->

      iv         = Forge.random.getBytesSync(AesCryptoService.BLOCK_CIPHER_KEY_SIZE)
      buffer     = Forge.util.createBuffer(uint8)
      ciphertext = @abstractCryptoService.encryptBuffer(@key, iv, buffer)

      return new BlockCiphertext {
        iv       : btoa(iv)
        salt     : btoa(Forge.random.getBytesSync(0))
        contents : btoa(ciphertext)
      }

    decrypt: (blockCipherText) ->

      Validator.validate(blockCipherText, BlockCiphertext, BLOCK_CIPHERTEXT_SCHEMA)

      iv       = atob(blockCipherText.iv)
      contents = atob(blockCipherText.contents)
      return @abstractCryptoService.decrypt(@key, iv, contents)

    decryptToUint8Array: (blockCipherText) ->



  # constants
  BITS_PER_BYTE = 8
  HMAC_HASH_FUNCTION = 'sha256'

  logger = Logger.get('AesCryptoService')

  computeHMAC = (key, iv, salt, ciphertext) ->
    try
      hmac = forge.hmac.create()
      hmac.start(HMAC_HASH_FUNCTION, key)
      hmac.update(iv)
      hmac.update(salt)
      hmac.update(ciphertext)
      hmacHash = hmac.digest().getBytes()
      return hmacHash
    catch e
      console.error('caught exception while computing HMAC')
      return null

  checkDataIntegrity = (key, iv, salt, ciphertext, tag) ->
    hmacHash = computeHMAC(key, iv, salt, ciphertext)
    return tag == hmacHash

  class AesCryptoService

