There is a significant growth of the peer-to-peer (P2P) systems over the last few years because of their high potential for sharing file among the peers. Selection of the optimal peer ensures high data transmission rate and reduced network cost. However, it is highly difficult to select the optimal peer because of the variation in the heterogeneous capacity and dynamic capacity of the peers. Efficient peer selection approach is highly required to overcome this difficulty. This paper proposes a particle swarm optimization (PSO)-based optimal peer selection approach for a highly secure and trusted P2P system, based on the bandwidth and trust level of the peers. File replication is performed to effectively tackle the overloading of the hot files. Replacement of the replicated file is performed, based on their demand rates. The success rate and bandwidth rate of the peer are computed. Bandwidth and trust-based PSO is applied to select the optimal peer. This improves the success rate for the peer transmission. After selecting the optimal peer, the replicated file is encrypted and transmitted to the selected peer. Finally, the replicated file is decrypted. Our proposed approach achieves minimum average query delay and ensures a highly secure and trusted environment for the P2P systems. The performance of the proposed approach is evaluated by comparing the proposed approach with the existing techniques. From the comparison results, it is clearly evident that the proposed approach achieves higher success rate and lower link stress, delay, communication overhead, finished time and network cost.