       encryptedKey = raw.slice 16, 16 + recipientKeyKytes
       @recipientKey.decrypt(encryptedKey)
     catch
-      throw new Error "Incorrect message length."
+      throw new DecryptionError "Incorrect message length."
 
   getDecryptedMessage: (iv, key, raw) ->
     recipientKeyKytes = @recipientKey.keyPair.cache.keyBitLength / 8

    encryptedMessage = @encryptMessage signedMessage, message, key, iv
    new Buffer(iv + encryptedKey + encryptedMessage).toString "base64"

exports.Decryption = class Decryption

  constructor: (@recipientKey, @senderKey) ->


    if @verify signature, message
      return [message, signature.toString()[0]]

    throw new InvalidMessageException "Invalid message signature"

  getIv: (raw) ->
    raw.slice 0, 16
