Recently, wireless sensor networks have been used extensively in different domains. For example, if the wireless sensor node of a wireless sensor network is distributed in an insecure area, a secret key must be used to protect the transmission between the sensor nodes. Most of the existing methods consist of preselecting keys from a key pool and forming a key chain. Then, the sensor nodes make use of the key chain to encrypt the data. However, while the secret key is being transmitted, it can easily be exposed during transmission. We propose a dynamic key management protocol, which can improve the security of the key juxtaposed to existing methods. Additionally, the dynamic update of the key can lower the probability of the key to being guessed correctly. In addition, with the new protocol, attacks on the wireless sensor network can be avoided.