LoRaWAN is a LPWAN (Low Power Wide Area Network) technology used in a large variety of Internet of Things (IoT) applications. The paper addresses the security concerns of data protection and data privacy in sensor networks that make use of the LoRaWAN (Long-Range Wide Area Network) protocol specification. In this context, this paper performs an in-depth analysis of the security aspects in LoRaWAN sensor networks. Additionally, a novel secure LoRaWAN network architecture is proposed. The architecture provides protected data transmission and prevents unauthorized access and data loss. Based on experimental results and security tests, recommendations are made concerning the best practices to be followed in order to provide secure data transmission and data privacy in applications built using the LoRaWAN protocol specification.