Wireless sensor networks (WSNs) are highly vulnerable to attacks for the limitation of constrained resource and communicating via wireless links, especially running in a hostile environment such as battlefields. In such situation, an adversary may capture any node compromising critical security data including keys used for confidentiality and authentication. Consequently, it is necessary to provide security services to these networks to ensure their survival. In this paper, we present an AVL treebased dynamic key management to enhance network security and survivability. Compared to previous security solutions, the salient advantage of our work addresses challenging runtime security issues using dynamic key management scheme which is nearly realtime key renewal. The approach can efficiently protect the network against attacks of eavesdropping or captured nodes compromise, is adopted to address challenging security issues of runtime WSN. Even if the adversaries crack WSN keys, the entire network still remains safety under the timely protection of the rekey mechanism.