Wireless <span>sensor networks (WSNs) are the sensors that are dispersed in a different location that can sense the accumulated data in real-time and send it to the central location for the process of data aggregation. During the transfer of the information using the data nodes from the WSNs to the central location, there may be chances that the data node could be compromised by sensor failure or by an attack from a malicious user. To overcome this problem, we propose a two-phase secure data collection (TPSDC) technique for wireless sensor networks which provides confidentiality and integrity for the data nodes that are being sent to the central location and also during the data aggregation in the central location. Various existing methods have been proposed to secure the data when sent from the WSNs to the internet of things (IoT) devices but they lack to provide both confidentiality and integrity at the same time. Hence our model provides both integrity and confidentiality by providing security to the data nodes. Experimental results show that our model TPSDC performs better in terms of misclassification rate, detection rate, throughput, network lifetime analysis of the node, and communication overhead of the node when compared with the existing methods.</span>