Wireless sensor networks (WSNs) have developed during the past twenty years as a result of the accessibility of inexpensive, short-range, and simple-to-deploy sensors. A WSN technology sends the real-time sense information of a specific monitoring environment to a backend for processing and analysis. Security and management concerns have become hot topics with WSN systems due to the popularity of wireless communication channels. A large number of sensors are dispersed in an unmonitored medical environment, making them not safe from different risks, even though the information conveyed is vital, such as health data. Due to the sensor′s still limited resources, protecting information in WSN is a significant difficulty. This paper presents a hierarchical key management method for safeguarding heterogeneousWSNs on hybrid energy-efficient distributed (HEED) routing. In the proposed method, the Bloom scheme is used for key management and a pseudo-random number generator (PRNG) to generate keys in an efficient method to keep sensor resources. In addition, using cipher block chaining-Rivest cipher 5 (CBC-RC5) in this method achieved cryptography goals such as confidentiality. A comparison is made between the proposed and existing methods such as dynamic secret key management (DSKM) and smart security implementation (SSI) under the same circumstance to determine the performance of the new method. The data transmission in WSN consumes about 71 percent of a sensor′s energy, while encryption computation consumes only 2 percent. As a result, our method reduces the frequency with which data transmissions are made during the key management process. The simulation findings demonstrated that, in comparison to earlier techniques, the proposed method is significantly more secure, flexible, scalable, and energy-efficient. Our proposed method is also able to prevent classifications of node capture attacks.