Device to Device (D2D) communications appear like an emergency solution for the Public Safety Network (PSN) when the LTE cell range is limited. D2D networks can use the unlicensed frequency bands, as this makes their transmissions cheaper and easier to deploy. Therefore, the development of this technology must deal with the security challenge. On the one hand, it is important to know how to design a secure D2D solution within the small cells, and on the other hand, the new scheme needs to deal with the problem of radio resources limit, since it will be used during emergency situations. This paper develops a new algorithm, named Generalized Secure Network Coding-based Data splitting algorithm (G-SNCDS), to ensure a secure data transmission for Public Safety D2D communications over LTE Heterogeneous Networks (HetNets) and 5G networks, without using additional radio resources. Our approach consists of performing Network Coding (NC) data packets transmissions based on a new Data Splitting (DS) technique, which we developed, based on a constructed butterfly effect that uses a new Butterfly network algorithm that we propose. Our solution enhances the security without affecting the level of Quality of Service (QoS). Thus, it is more suitable when network resources are limited. The simulation results show that our approach provides a secure D2D communication without increasing the overhead in the network.