Wireless Sensor Network (WSN) are spatially distributed sensor nodes to monitor physical or environmental conditions, such as temperature, sound, pressure, etc. Wireless Sensor Networks are used in many applications in military, ecological, and health-related areas. These applications often include the monitoring of sensitive information such as enemy movement on the battlefield or the location of personnel in a building. Security is therefore important in WSNs. However, WSNs suffer from many constraints, including low computation capability, small memory, limited energy resources, susceptibility to physical capture, and the use of insecure wireless communication channels. These constraints make security in WSNs a challenge. In this article we present a survey of security issues in WSNs. First we outline the constraints, security requirements, and attacks with their corresponding countermeasures in WSNs. We then present a holistic view of security issues. These issues are classified into two categories: cryptography and secure routing. Along the way we highlight the advantages and disadvantages of various WSN security protocols and conclude with possible future research on security in WSNs.