Task allocation and scheduling schemes have been widely used for the emerging computation-intensive Internet of Things applications to achieve energy efficiency and meet the latency requirement. However, collaborative task execution brings a high risk of security threats, e.g., malicious attacks or eavesdropping, because communication over wireless channel is naturally vulnerable. This work addresses the task allocation problem considering security threats. Firstly, it develops a general framework for the problem of task allocation with data security termed TADS. Besides the energy and latency requirements, TADS also considers the data confidentiality required by both the surrounding environment and the application tasks' criticality. Then, this work proposes a security-aware task allocation algorithm, GASA, by combining the genetic algorithm and the simulated annealing approach to distribute the application tasks across the network efficiently. Extensive simulations have been performed in various testing environments to validate the proposed GASA algorithm. The results illustrate the considerable performance improvements compared with the existing approaches in terms of algorithm convergence rate, network lifetime extension, etc.