A resource-efficient key management protocol is essential for security-sensitive applications in wireless sensor networks (WSN). Moreover, the dynamic pair-wise key and group key management protocols are also important for long-lived and mobile WSN. In this paper, a Two-layered Dynamic Key Management (TDKM) approach for cluster-based WSN (CWSN) is proposed. Both pair-wise key and group key are distributed in three rounds for key material exchange without encryption/decryption and exponentiation operations in TDKM. In theoretical analysis, TDKM is compared with other key management protocols to show its efficiency. Finally, the relationships between the number of groups and the system performance including key generation overhead, network security, and secured data transmission overhead in CWSN are analyzed.