The Wireless Sensor Networks (WSNs) are characterized by their widespread deployment due to low cost, but the WSNs are vulnerable to various types of attacks. To defend against the attacks, an effective security solution is required. However, the limits of these networks’ battery-based energy to the sensor are the most critical impediments to selecting cryptographic techniques. Consequently, finding a suitable algorithm that achieves the least energy consumption in data encryption and decryption and providing a highly protected system for data remains the fundamental problem. In this research, the main objective is to obtain data security during transmission by proposing a robust and low-power encryption algorithm, in addition, to examining security algorithms such as ECC and MD5 based on previous studies. In this research, the Energy Saving and Securing Data algorithm (ESSD) algorithm is introduced, which provides the Message Digest 5 (MD5) computation simplicity by modifying the Elliptic Curve Cryptography (ECC) under the primary condition of power consumption. These three algorithms, ECC, MD5, and ESSD, are applied to Low Energy Adaptive Clustering Hierarchy (LEACH) and Threshold-sensitive Energy Efficient Sensor Network Protocol (TEEN) hierarchical routing algorithms which are considered the most widely used in WSNs. The results of security methods under the LEACH protocol show that all nodes are dead at 456, 496, and 496, respectively, to ECC, MD5, and ESSD. The results of security methods under the TEEN protocol show that the test ends at 3743, 4815, and 4889, respectively, to ECC, MD5, and ESSD. Based on these results, the ESSD outperforms better in terms of increased security and less power consumption. In addition, it is advantageous when applied to TEEN protocol.