def decrypt(message, hash: nil)
      # 0
      message = Base64.decode64(message)
      hmac = message[0..63] # 64 bits of hmac signature

      case
      when hash && hmac != hash
        raise Error, "Provided hash mismatch for encrypted file!"
      when hmac != hmac_signature(message[64..-1])
        raise Error, "HMAC signature mismatch for encrypted file!"
      end

      # 1
      rsa_encrypted_aes_key = message[64..319]  # next 256 bits
      rsa_encrypted_aes_iv  = message[320..575] # next 256 bits
      aes_encrypted_message = message[576..-1]

      # 2
      aes_key = @rsa.private_decrypt rsa_encrypted_aes_key
      aes_iv  = @rsa.private_decrypt rsa_encrypted_aes_iv

      # 3
      @cipher.reset
      @cipher.decrypt
      @cipher.key = aes_key
      @cipher.iv  = aes_iv
      content = @cipher.update(aes_encrypted_message) + @cipher.final

      { signature: hmac, content: content }
    rescue OpenSSL::OpenSSLError => e
      raise Error.new(e.message)
    end
def decrypt(message, hash: nil)
      # 0
      message = Base64.decode64(message)
      hmac = message[0..63] # 64 bits of hmac signature

      case
      when hash && hmac != hash
        raise Error, "Provided hash mismatch for encrypted file!"
      when hmac != hmac_signature(message[64..-1])
        raise Error, "HMAC signature mismatch for encrypted file!"
      end

      # 1
      rsa_encrypted_aes_key = message[64..319]  # next 256 bits
      rsa_encrypted_aes_iv  = message[320..575] # next 256 bits
      aes_encrypted_message = message[576..-1]

      # 2
      aes_key = @rsa.private_decrypt rsa_encrypted_aes_key
      aes_iv  = @rsa.private_decrypt rsa_encrypted_aes_iv

      # 3
      @cipher.reset
      @cipher.decrypt
      @cipher.key = aes_key
      @cipher.iv  = aes_iv
      content = @cipher.update(aes_encrypted_message) + @cipher.final

      { signature: hmac, content: content }
    rescue OpenSSL::OpenSSLError => e
      raise Error.new(e.message)
    end
0. Base64 decode the encrypted message
 1. Split the string in to the AES key and the encrypted message
 2. Decrypt the AES key using the private key
 3. Decrypt the message using the AES key