In wireless sensor networks (WSNs), massive amounts of nodes, volatile network topology and limited resources (such as energy, computing power, storage, bandwidth, and so on) make the traditional security scheme cannot be directly applied to WSNs. Identity-based encryption (IBE) is becoming a hot research topic since it does not need PKI and complicated certificate operations. In this paper, a novel identity-based security scheme is proposed on the basis of IBE. Each cluster head can perform as a private key generator (PKG) in case that the only PKG is captured, which will lead to the entire network disabled. The proposed scheme can reduce the consumption of key resources and improve the security of the entire network by dispersing PKG function. The analysis shows that the scheme is more secure and efficient by comparing with traditional public key and symmetric key techniques.