Networks consisting of wireless sensors are extensively used in many applications. Decentralized Erasure Codes (DEC) were introduced to store the sensed data in the wireless sensor network itself before transmitting the sensed data from wireless nodes to gateway or query nodes. Data at the failed nodes can be reconstructed by accessing other nodes in the network in DEC setup. In a traditional DEC setup, it is required to access k nodes out of n nodes to reconstruct the data at the failed node. Also, the reconstruction at failed node is subjected to intruder attacks raising security concerns. To reduce the number of nodes required to reconstruct the data at failed nodes and to ensure communication security, in this paper, decentralized erasure codes were constructed from optimal locally recoverable codes and Blom’s key pre-distribution protocol, which exploits the generator matrix nature of constructed code, was implemented. From the simulations, we can infer that the proposed scheme performs better than other existing methods that use Reed–Solomon codes in terms of network load and error count per sent packet. Furthermore, it is shown that the proposed scheme ensures secure and efficient communication between nodes to overcome intruder interference. © 2019, Springer Science+Business Media, LLC, part of Springer Nature.