Advances in electronics and wireless communication technologies have enabled the development of large-scale wireless sensor networks (WSNs). There are numerous applications for wireless sensor networks, and security is vital for many of them. However, WSNs suffer from many constraints, including low computation capability, small memory, limited energy resources, susceptibility to physical capture, and the lack of infrastructure, all of which impose unique security challenges and make innovative approaches desirable. In this paper, we present a survey on security issues in wireless sensor networks. We address several network models for security protocols in WSNs, and explore the state of the art in research on the key distribution and management schemes, typical attacks and corresponding countermeasures, entity and message authentication protocols, security data aggregation, and privacy. In addition, we discuss some directions of future work.