Device to device (D2D) communication has emerged as a potential candidate for next-generation communication networks to support higher data rates and minimize power consumption. The spectral and energy efficiency of D2D communication can further be improved using cognitive radio (CR) and radio frequency energy harvesting (RF-EH) technologies. Therefore, in this paper, a sum throughput maximization problem for a CR assisted D2D network is modeled considering the RF-EH mechanism. A joint optimization problem is formulated for sum-rate maximization of cellular and D2D users by considering power allocation, channel assignment, user pairing and transmission time ratio allocation. Then, the problem is transformed into a standard convex optimization problem subject to power constraints at individual nodes, interference constraint, and the individual rate. Furthermore, the secrecy capacity requirements of cellular and D2D nodes are also considered. The duality theory is used to decompose the problem into multiple sub-problems and Karush-Kuhn-Tucker conditions are exploited to provide the solution of the sub-problems. The simulation results are provided for the validation of our proposed schemes.