A device of wireless sensor networks (WSNs) has restricted computational resources, and is always deployed in a harsh, unattended or hostile environment. This investigation presented the time-division secret key protocol for wireless sensor networking to detect denial-of-service (DoS) attack. Simulation results indicate that detect DoS attack and cipher function can be effectively applied to WSNs. The simulation results indicate that after running for 400 s, a detection jamming scheme still alive with 160 nodes, but the one with only 50 nodes does. This result demonstrates that a detection jamming scheme can extend the network lifetime when the WSN security is adopted.