Wireless sensor networks (WSNs) have been the subject of intensive research in the past few years and the backbone of most maximum present information technology. WSNs have been employed in various applications such as track monitoring battlegrounds in military fields and patients’ medical requirements in the civilian field. The wireless sensor networks are always randomly distributed in an open area (hostile), pervasive environment, and open media channel. Thus, WSNs are vulnerable to several species of attacks. Moreover, messages may be easily intercepted or altered because the transmission is not secure, hence effective key management scheme is strongly needed to reduce the risks. Cryptography methods are a crucial aspect of WSNs to reach security goals. In this paper, we propose an efficient and secure message transmission scheme that combines the Knapsack algorithm with the Diffie-Hellmann process to encrypt messages. The results and analysis show that the proposed scheme is efficient and it achieves most of the security goals providing high privacy and security. It is also resilient against some of the well-known attacks.