## 1 Introduction  
Sensor networks, which usually comprise plenty of tiny sensor nodes with limited resources, have been demonstrated to be useful in most applications, such as battlefield communication and emergency search-and-rescue scenarios. Due to the advancement of robotics and microchip technology, a sensor node may also possess moving capability. Mobile sensor networks (MSNs) are composed of sensor nodes with moving capability. The moving characteristic of a mobile sensor node, _i.e._, the mobility model, is usually described as change in position with an upper speed limit and moving trajectory. Taking into consideration nodes' mobility, it is desirable, but more challenging, to design efficient and effective schemes against attacks in mobile sensor networks. One of the most classic malicious attacks is a replication attack. Under this kind of attack, one node could be captured and many replicas of the compromised node could be made by using the same ID. These malicious nodes could get some information by accessing the network. Most communication protocols rely heavily on message forwarding in MSNs. In a wormhole attack, these replicas of the compromised node may collude with each other to destroy the communication protocols. This makes it difficult to ensure network security. In most realistic scenarios, nodes constantly keep moving in the network, and some significant areas might require higher security levels than other areas. The proposed mechanism in this paper satisfies the above two requirements at the same time. Detailed illustrations will be provided in Section 4. The concept of a location-based key (LBK) [1] was first put forward in 2006. A LBK is used in static wireless networks. In this situation, each node has a private key which is bound to its ID and geographic location to detect attacks. Since then, the location information of nodes has gradually become a crucial factor for MSNs. Some schemes have exploited the parameter related to the location information [2; 3; 4; 5; 6] to resist replication attacks. Though the mechanisms based on LBK could resist some kinds of attacks, they are not suitable for dynamic networks. The positions of nodes are changing all the time in dynamic networks, so a LBK might be illegitimate at some point. [PERSON]. [3] proposed a mechanism for detecting a replication attack by using the location information of nodes. Nodes exchange their neighbor lists to find out contradictions. Every node plays two roles: Ordinary node and witness node. This mechanism is successfully used in TDD and SDD to resist replication attacks. Much later, a localized mechanism [6] was proposed to resist replication attacks, but it is only used in dynamic networks. The previous studies may only be suitable for a single network environment and often require large amounts of storage. To address many of these problems, this paper presents a layered location-based security mechanism for MSNs. This paper aims to develop a security mechanism for MSNs. Nodes will not update their location-based private keys until moving out of the special areas, which are called moving security areas (MSA). What is more, the parameter \(\Delta\), which is the radius of the circular area MSA, can be regulated to satisfy different security needs. The main contributions from our work are as follows. Firstly, we design a scheme in which the locations of nodes are embedded into their location-based public keys, so that the locations can be authenticated to resist location-based malicious attacks. Secondly, we analyze the effective range of the location-based keys of mobile nodes, design the update scheme of the location-based keys, and resolve the problem that location-based keys are difficult to apply in mobile sensor networks. Thirdly, a layered detection framework is proposed in our scheme. Inside the effective moving security areas of the nodes' location-based keys, the detections could be executed by exchanging the nodes' local information.